From: Trans Date: 2008-12-01T01:47:11+09:00 Subject: Re: Enumerable#select used to return actual values On Nov 30, 6:45 am, Trans wrote: > On Nov 29, 10:39 pm, Mike Austin <"mike[nospam]"@mike-austin.com> > wrote: > > > I'm pretty sure select used to use the actual value of the called block, > > instead of treating it as just a truthy/falsey boolean.  I know this is > > unconventional, but it's a really nice, compact way of expressing map and > > filter in one shot, like list comprehension: > > > (1..10).select { |a| a * a if a > 5 } > > > Was it ever there, or did I just have a dream about it?  It's easy to > > implement... just wondering. > > I always thought it would be nice if Ruby had a method for this. > Facets' provides #compact_map. Perhaps not the sexiest name (once upon > a time it was called #collect_if), but it's describes the behavior > properly. Oh, I remember why it is called #compact_map now, rather then some more concise name. And I've been meaning to bring it up again. Why not let #compact itself take a block to do this? T.