What is ||= (or-equals) operator in Ruby?
In Ruby ||= (or-equals) is a "conditional assignment operator".
E.g. a ||= b
Simply, a ||= b means If a is undefined, nil or false, assign b to a. Otherwise, keep a intact.
a ||= b
is equivalent to
a || a = b
and not equivalent to
a = a || b
Ruby's short circuit evaluation means that if a is defined and evaluates to true, then the right hand side of the operator is not evaluated, and no assignment takes place.
This distinction is unimportant if a and b are both local variables, but is significant if either is a getter/setter method of a class.
you can try more........
A common misconception is that a ||= b is equivalent to a = a || b, but it behaves like a || a = b