On Sat, 2005-11-19 at 05:17 +0900, mark wrote:
> Hi,
> Is there an explanation somewhere of all the weird operators in ruby
> such as ||= and exactly what they do?
> Apologies if this is a faq but I'm unable to google anything.
> 



a <op>= b

is completely equivalent to

a = a <op> b

So a ||= b means a = a || b. a || b evaluates to a if a is not nil or
false and to b otherwise. The side effect is that a is unchanged if not
nil or equal to b otherwise.

One great use for it is default value assignment:

@a ||= a_default_value

@a is assigned the default value if a has no value yet (nil).

HTH,
Guillaume.