From: Brian Candler Date: 2012-10-31T22:55:45+09:00 Subject: Re: bug?: local variable created in if modifier not available in modified expression Mean L. wrote in post #1082116: > Ruby parses left to right, so it see "lo" on the assignment side of the > if. Since no local variable "lo" has been encountered yet it must be a > method. Ruby then encounters the assignment to lo and creates the local > variable. > _____________________________________ > > I can't say this makes sense to me. Ruby otherwise is a dynamic > language, but with respect to local vars it's suddenly static, and the > parser wants to identify all local vars in one left to right parse pass, > before the code is run. Two important reasons: 1. It would be enormously inefficient if every time you invoked an expression like 'a' you had to decide at run-time whether it was a variable or a method call 2. It is much easier to inspect a piece of code and be able to say with certainty at any point whether 'a' is a variable or method call. (This is also a good reason why class and def start new scopes; you never need to look outside of the current method to resolve the variable/method ambiguity) -- Posted via http://www.ruby-forum.com/.