The or-equals operator
This one feels like a simple concept to teach, but an easy one to forget.
The or-equals operator ||=
allows a value to be assigned to a variable if and only if that variable evaluates to nil
or false
.
Consider, for example:
This can be expressed as:
So be careful if false
is a valid value, otherwise it can be overtaken with or-equals.