From: Nobuhiro IMAI Date: 2008-05-08T08:52:57+09:00 Subject: [ruby-dev:34606] Re: Array#mapがEnumeratorを返さない いまいです。 From: rubikitch_at_ruby-lang.org Date: Thu, 8 May 2008 04:32:52 +0900 > Array#mapでブロックをつけない場合にEnumeratorを返しません。 > > RUBY_VERSION # => "1.9.0" > [8,3,9].map # => # > [8,3,9].map.with_index{|x,i| [x*x, i]} # => [[64, 0], [9, 1], [81, 2]] > > RUBY_VERSION # => "1.8.7" > [8,3,9].map # => [8, 3, 9] > [8,3,9].map.with_index{|x,i| [x*x, i]} # => > > # ~> -:11: undefined method `with_index' for [8, 3, 9]:Array (NoMethodError) NEWS に注記がありますね。 (...) Return an enumerator if no block is given. Note that #map and #collect still return an array unlike Ruby 1.9 to keep compatibility. (...) [8,3,9].enum_for(:map).with_index{|x,i| [x*x, i]} でしょうか。 -- Nobuhiro IMAI Key fingerprint = F39E D552 545D 7C64 D690 F644 5A15 746C BD8E 7106