enumerator.each_with_object [] do |value, memo|
   memo << value if value.nil?
end


On Fri, Dec 31, 2010 at 6:50 PM, Michel Demazure <michel / demazure.com>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/.
>
>