12 ms·
Or at the very least you are likely to get terribly confused. The posters confusion has absolutely nothing to do with conditionals and modifiers and is entirely
by pvg 17y ago
Or at the very least you are likely to get terribly confused. The posters confusion has absolutely nothing to do with conditionals and modifiers and is entirely about Ruby variable definition and scoping semantics. In fact if you broke one of his examples by reversing the conditional, the variable, the assignment of which is never evaluated is still defined.
>> a = 1
=> 1
>> unless defined? a
>> b = 5
>> end
=> nil
>> defined? b
=> "local-variable"
>> b
=> nil
- angilly 17y agowhoa. didn't see that coming.
- aaronblohowiak 17y agoRight, variable definition happens as early as when the code is parsed, even if it is never used.