From: Gary Wright Date: 2007-09-19T04:07:28+09:00 Subject: Re: Variable / Method Ambiguity On Sep 17, 2007, at 12:08 PM, Jeffrey 'jf' Lim wrote: > On 9/17/07, David A. Black wrote: >> Hi -- >> >> On Mon, 17 Sep 2007, Summercool Summercool wrote: >> >> >>> >>> (as described in the PickAx2 book, p. 329) >>> >>> So at first I thought a Ruby program is interpreted? If >>> interpreted, >>> then the interpreter will see the "a = 1" at first as treat "a" as a >>> variable, and then the second time it sees "a", the interpreter >>> should >>> treat it as a variable again, not as a method. >> >> No, because there's no such variable in scope. The second time >> through >> the loop, there's no assignment to a, and the first variable a has >> gone out of scope. > > so this is lexical scoping, then? No, it is just that Ruby has a single-pass parser. The parser needs to decide if an identifier is a local variable or a zero-argument method before it has seen the entire text of the file (no look-ahead). Until the parser sees an assignment of the form "a = ..." it assumes that 'a' is a method call. So if/then/else statements do *not* create new lexical scopes. Gary Wright