Once set, variables are always defined
When you set a variable in a section of code that is never executed, the variable will still be defined.
if false a = 'whatever' end puts a # => "nil" # Does NOT raise 'NameError: undefined local variable or method `a' for main:Object'
This post was submitted by Olivier El Mekki.
[shared via Ruby Quicktips]
- — 4 notes
-
fitzpatrickyou834 liked this
-
murphytii0 liked this
-
ybrown48cug liked this
-
samoli posted this