From: "David A. Black" Date: 2008-12-01T16:53:56+09:00 Subject: Re: Enumerable#select used to return actual values Hi -- On Mon, 1 Dec 2008, 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. But it's in Enumerable already, in 1.9. >> RUBY_DESCRIPTION => "ruby 1.9.0 (2008-11-12 revision 20227) [i386-darwin9.5.0]" >> Enumerable.instance_methods(false).grep(/object/) => [:each_with_object] David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL See http://www.rubypal.com for details Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)