B
Brian Candler
This seems a bit of an anomoly:
It seems that Array#map and Enumerable#map without a block return just
an Array. However most other Enumerable methods return an Enumerator,
even #each (which is pretty useless, since the Enumerator maps #each to
#each)
=> "ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]"
=> [1]
Anybody got a good explanation for this?
=> [1, 2, 3] # I was expecting [2, 4, 6]x = [1,2,3].map
x.each { |y| y*2 }
It seems that Array#map and Enumerable#map without a block return just
an Array. However most other Enumerable methods return an Enumerator,
even #each (which is pretty useless, since the Enumerator maps #each to
#each)
=> "ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]"
=> [1, 2, 3][1,2,3].each=> # said:[1,2,3].map => [1, 2, 3]
[1,2,3].collect
=> [1]
Anybody got a good explanation for this?