From: Kirk Haines Date: 2004-04-24T02:02:36+09:00 Subject: Re: attr_accessor vs. local variable On Sat, 24 Apr 2004, Jim Weirich wrote: > I stand corrected. References to 'x' that are lexically before the > assignment are treated as method calls. References after the the > assignment are treated as local variables. But notice it has nothing to > do with executeing the assignment. > > That leads to the following example ... > > $ cat x.rb > def x > "METHOD CALL" > end > def f > i = 2 > while i > 0 > puts x > x = "LOCAL VARIABLE" > puts x > i -= 1 > end > end > f > $ > $ ruby x.rb > METHOD CALL > LOCAL VARIABLE > METHOD CALL > LOCAL VARIABLE Great example! I would not have expected it to work that way, though I understand now that I see it. Thanks much. Kirk Haines