I'm trying to evaluate the expression (a=10) || (rr=20)
while the rr variable is not defined
so typing rr
in the ruby console before evaluating the previous expression returns
rr
NameError: undefined local variable or method `rr' for main:Object
from (irb):1
from :0
When I write the expression (a=10) || (rr=20)
it returns 10, and when I write rr afterwards it says nil
(a=10) || (rr=20)
rr # => nil
so, why is this happening? Shouldn't rr be defined only if the second argument of the || operator is evaluated, which should be never based on the documentation?
a+1 if a = 5
. You might expect that it will set a to 5 and then return 6, but actually it will seta
and THEN complain abouta
being undefined. – Sarraceniaceous