From: Robert Klemme Date: 2012-10-31T18:49:24+09:00 Subject: Re: bug?: local variable created in if modifier not available in modified expression On Wed, Oct 31, 2012 at 1:53 AM, Mean L. wrote: > 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. > > so even though at runtime > > (a if a = 1) > > local var 'a' already exists before it's read, It could, but it doesn't - because of the current semantics. :-) > the parser has statically > bound the first 'a' to a method lookup path. > > So the question is, why in a dynamic language is local variable binding > static? Is it a perf optimization? Just a guess: it's probably simpler to implement. The decision when a variable exists can be made solely based on textual order of the source code and does not need to take into account how expressions are evaluated which is a much more complicated thing to evaluate. I guess, Matz figured it's not worthwhile for the few corner cases. And the community has learned to live with it pretty well, I'd say. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/