Hi --

On Tue, 25 Mar 2008, Adam Akhtar wrote:

>
>> The most common idiom is:
>>
>>    (hash[key] ||= []) << value
>>
>
> Thanks for the reply. Can I ask what these || mean..in this case do they
> mean OR???

Yes. This:

   a ||= b

is the same as:

   a or a = b

I used to describe it like this:

   a = a || b

but there are some edge cases where that doesn't apply (having to do
with hash defaults, actually, but you don't need to worry about it in
this case). Matz clarified it with the "or" version at RubyConf last
year.

> does anyone have any good links on using the use of arrays with hashes
> in this manner?

I don't know -- I just sort of use them :-)


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS   April 14-17          New York City
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
See http://www.rubypal.com for details and updates!