From: David Masover Date: 2009-09-15T10:15:51+09:00 Subject: Re: [1,2,3].map.with_object(3){|v|v+3} #=> 3 Is this a bug? On Sunday 13 September 2009 09:19:31 pm ErMaker wrote: > At ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-mswin32_90] > > Ruby runs like this. > > >> [1,2,3].map.with_object(3){|v|v+3} > > => 3 > > >> [1,2,3].each.with_object(3).map{|v|v+3} > > => [4, 5, 6] That makes sense, now that I know what with_object does. > I think that is better to use. > > >> [1,2,3].map.with_object(3){|v|v+3} > > => [4, 5, 6] > > Is it a bug? I doubt it -- map is the only iterator that returns the results of each iteration. In fact, if you look at what with_object does, it's doing exactly what it's designed to: irb(main):041:0> [1,2,3].each.with_object({}){|x,h| h[x] = x**2} => {1=>1, 2=>4, 3=>9} I don't see why you want to do with_object at all -- your above example would work just fine as: [1,2,3].map{|v|v+3} If you wanted to use a variable, you could do that too: x = 3 [1,2,3].map{|v|v+x} I can't imagine why you'd want to have the behavior of foo.with_object.map, ever. Could you please give more context?