OK so the answer is that the `bar` at line 7 is interpreted as referring to the method, whereas the `bar` at line 11 is interpreted as referring to the local variable which the parser saw introduced at line 8
-
-
Show this thread
-
Note that only the parser saw a new local variable `bar` being introduced at line 8. Line 8 is never actually executed
Show this thread -
Note also that the local variable `bar` introduced at line 8 has indescribably awful scope: it encompasses lines 8, 9, 10 and 11, but not 7
Show this thread -
Of course, every programming language has horrors such as this baked into it. The real question is this: are there industry standard Ruby linting tools in common use, which throw a build failure over such code? There are for e.g. JavaScript
Show this thread
End of conversation
New conversation -
-
-
oh, hell. because ruby sets a local variable "bar" even though the inner if hasn't been called?
-
Yes, line 8 creates a local variable `bar` with indefensibly awful scope - it encompasses lines 8 to 11 but not 7
End of conversation
New conversation -
-
-
aargh
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.