In fact, a ||= "something" is equivalent to a = a || "something"
What does this mean? a = a || "something" -> left operand in a || "something" isn't defined, evaluates to nil, which is false, then right operand needs to be evaluated as well, so assigning a value.
That's an idiom that came from C language. Try that in irb and you see there's no error at all.
In fact,
a ||= "something"
is equivalent toa = a || "something"
What does this mean?
a = a || "something"
-> left operand ina || "something"
isn't defined, evaluates to nil, which is false, then right operand needs to be evaluated as well, so assigning a value.That's an idiom that came from C language. Try that in irb and you see there's no error at all.