Bug #11659
closedStrange behavior setting previously-undefined local variables with a statement modifier
Description
Consider a previously-undefined local variable var1:
Consider previously-undefined local variables var1 and var2:
Consider a previously-undefined local variable var3:
Consider a previously-undefined local variable var4:
Oops! Why is var4 nil? Logically, considering the prior examples, it should be 'default'. Or are we missing something?
http://stackoverflow.com/questions/33537059/unless-defined-is-not-working-in-my-code
Updated by Hanmac (Hans Mackowiak) over 10 years ago
because you got a typo for var2, see the var1 inside.
the problem there is that var got defined from the parser before the code is run, so when it does check for defined, var4 is already defined
also checkout:
Updated by mwpastore (Mike Pastore) over 10 years ago
That's not a typo. :-) I wanted to intentionally compare and contrast between a scenario where the same variable was being checked and set (#2) and a scenario where two different variables are in play (#4).
I understand about the parser now, and in fact found another question/answer on SO that explains it in a similar manner. So it's not a bug, per se. It is kind of a Ruby "WTF", though, and in this humble Rubyist's opinion violates POLA pretty badly.
Updated by jeremyevans0 (Jeremy Evans) about 7 years ago
- Status changed from Open to Rejected