Variables are local to a function, class or module, a proc , block.
There is an expression in ruby if, and branches do not have their own volume.
Also note that whenever the parser sees the purpose of a variable, it will create a variable in the scope even if this code path is not executed :
def test if false a = 1 end puts a end test
It is similar to JavaScript, although it does not raise the variable to the top of the field:
def test puts a a = 1 end test
So, even if what you said was true, it still would not be nil .
Karoly Horvath
source share