Saturday, March 28, 2009

Variables are created and set to nil as soon as they are mentioned

Tim:~> irb
>> local_variables
=> ["_"]
>> if false
>> some_variable = :yahoo
>> end
=> nil
>> some_variable
=> nil
>> local_variables
=> ["_", "some_variable"]

Isn't that interesting? When I define a variable within an if statement that will never be entered (and thus the variable will never be assigned to :yahoo), it is listed as a local variable and set to nil.


No comments: