Hi Norbert:
An idiom that I use frequently is:
h = {}
(h[key] ||= []) << item
which essentially says "if hash h[key] is nil, create an empty array for
that key. then push item onto the array. for example:
>> h = {}
=> {}
>> (h["cats"] ||= []) << "Jellicle"
=> ["Jellicle"]
>> (h["cats"] ||= []) << "Mr. Mistoffelees"
=> ["Jellicle", "Mr. Mistoffelees"]
Is that what you were looking for?
- ff
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en.