From: Guten Date: 2010-12-31T22:11:52+09:00 Subject: Re: a common idiom --20cf300258cc99d3d00498b48b6b Content-Type: text/plain; charset=ISO-8859-1 enumerator.each_with_object [] do |value, memo| memo << value if value.nil? end On Fri, Dec 31, 2010 at 6:50 PM, Michel Demazure wrote: > Michael Fellinger wrote in post #971622: > > compact > Yes ! I knew there was a method, but forgot the name, browsed thru > Flanagan-Matz, and did not find it. > > > results = [] > > some.each do |value| > > results << value.operation if value.condition? > > end > > Yes, returning results, but I try to avoid this extra variable. I > dislike (question of taste) the pattern > def ... > res = [] > ... > res << > ... > res > end > > Another way is using tap > > Array.new.tap do |res| > ... > end > > A bit snob, no ? > > -- > Posted via http://www.ruby-forum.com/. > > --20cf300258cc99d3d00498b48b6b--