Alex LeDonne
12/12/2007 12:40:00 AM
On Dec 11, 2007 7:15 PM, Michael Boutros <me@michaelboutros.com> wrote:
> Hello! More and more I find myself having to do something like this:
>
> def some_method(foo)
> results = []
> foo.each {|f| results << f.reverse}
> return results
> end
>
> As you can see, that is some pretty ugly code, but it's also a common
> scenario. How can I make it a little less ugly?
>
> Thanks,
> Michael Boutros
If I understand your goal, that's what map is for:
foo.map {|f| f.reverse}
"map" can also be spelled "collect".
-A