On 10/03/2009, at 3:52 PM, Nick Partridge wrote:
> Symbol-to-proc, and the use of `&` to coerce things to procs:
>
> [1,2,3,4,5].select(&:odd?)
>
> Awww yeah.
Cute but wasteful, and now deprecated in all Rails core code because of
the extra (non-gc-able?) object it creates.
I like this for creating and adding to hash values consisting of an
array:
things_by_key = {}
things.each do |thing|
(things_by_key[thing.key] ||= []) << thing
end
or the same using inject...
Clifford Heath.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---