Try the following in irb: (I'm using Ruby 2.0.0-p247)
blah
#=> NameError: undefined local variable or method `blah' for main:Object
if false
blah = 'blah'
end
#=> nil
blah
#=> nil
I'm surprised that blah
is assigned nil
even when the if
condition evaluates to false
.
I thought the code within if
is skipped as the condition evaluates to false
.
Could someone with Ruby internals knowledge kindly explain how this happened?
Thank you