P
Paul Sholtz
I'm looking at some source code, to try and understand it.
There's a variable "weight", and then there's this call:
weight ||= 100
which I take to be equivalent to:
weight = weight || 100
(i.e., performing a logical OR between "weight" and 100).
What I think this code means, is that the value that will be assigned to
"weight" will be either (a) "weight" (if weight has already been
assigned) or else (b) if "weight" is presently nil, then the value 100
will be assigned to "weight" instead.
Is this correct?
There's a variable "weight", and then there's this call:
weight ||= 100
which I take to be equivalent to:
weight = weight || 100
(i.e., performing a logical OR between "weight" and 100).
What I think this code means, is that the value that will be assigned to
"weight" will be either (a) "weight" (if weight has already been
assigned) or else (b) if "weight" is presently nil, then the value 100
will be assigned to "weight" instead.
Is this correct?