S
SpringFlowers AutumnMoon
if foo is undefined, it will throw exception when referred to... as in
try 1, 2, and 3 below. However, it won't throw exception when assigned
to himself... how is that interpreted?
irb(main):001:0> foo
NameError: undefined local variable or method `foo' for main:Object
from (irb):1:in `Kernel#binding'
irb(main):002:0> foo || 0
NameError: undefined local variable or method `foo' for main:Object
from (irb):2:in `Kernel#binding'
irb(main):003:0> bar = foo || 0
NameError: undefined local variable or method `foo' for main:Object
from (irb):3:in `Kernel#binding'
irb(main):004:0> foo = foo || 0
=> 0
irb(main):005:0> foo
=> 0
try 1, 2, and 3 below. However, it won't throw exception when assigned
to himself... how is that interpreted?
irb(main):001:0> foo
NameError: undefined local variable or method `foo' for main:Object
from (irb):1:in `Kernel#binding'
irb(main):002:0> foo || 0
NameError: undefined local variable or method `foo' for main:Object
from (irb):2:in `Kernel#binding'
irb(main):003:0> bar = foo || 0
NameError: undefined local variable or method `foo' for main:Object
from (irb):3:in `Kernel#binding'
irb(main):004:0> foo = foo || 0
=> 0
irb(main):005:0> foo
=> 0