You can expand a ||= 6
as
a || a = 6
So you can see that it use a
if a
is not nil
or false
, otherwise it will assign value to a
and return that value. This is commonly used for memoization of values.
Update
Thanks to the first comment for pointing out the true expansion of the ||=
(or equal) operator. I learned something new and found this interesting post that talks about it. http://dablog.rubypal.com/2008/3/25/a-short-circuit-edge-case