The following code snippet fully describes the problem, but I have to type all these extra words in to get SO to let me post it.
some_var ||= some_other_var do
# Does this run every time, or only sometimes?
stuff
end
The following code snippet fully describes the problem, but I have to type all these extra words in to get SO to let me post it.
some_var ||= some_other_var do
# Does this run every time, or only sometimes?
stuff
end
Such code will be evaluated just like any other with a ||=
operator. If some_var
is nil
or false
the function will run and return value will be assigned to some_var
; otherwise the value of some_var
will be returned. See What does ||= (or-equals) mean in Ruby? for reference.