From: Trans Date: 2008-12-01T09:01:41+09:00 Subject: Re: Enumerable#select used to return actual values On Nov 30, 6:24 pm, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Enumerable#select used to return actual values" >     on Sun, 30 Nov 2008 19:47:13 +0900, "David A. Black" writes: > > |(0..10).each_with_object([]) {|e,a| a << (e * e) if e > 5 } > | > |Basically inject with a sticky accumulator. > > #each_with_object is an interesting concept.  Maybe we can add it to > the Enumerable if we can come up with a better name. I take it that #each_with_object returns the accumulator, ie. a = (0..10).each_with_object([]) {|e,a| a << (e * e) if e > 5 } Since in 1.9 the block parameter is local to the block. As for a better name, maybe #each can just take an argument. (0..10).each([]) {|e,a| a << (e * e) if e > 5 } Or there's #accumulate, although the object doesn't necessarily have to be used according to that meaning. Do you remain against the idea of #compact taking a block? T.