From: dblack@... Date: 2003-05-06T10:31:32+09:00 Subject: Re: Variable/Method ambiguity Hi -- On Tue, 6 May 2003, Gennady wrote: > Pickaxe p.212 explains the subject well enough, however here's an interesting case: > > class Test > def name=(name) > puts "Called 'name=' ..." > end > def test > name = "aaa" > end > end > > Test.new.test > > I would expect to see "Called 'name=' ...", as Ruby can realize here > that method "name=" is available and call it. However, nothing is > printed, meaning that an assignment to local variable "name" took > place. > > Is it only me who thinks that such behaviour is inconsistent? I don't think it's inconsistent. I think it would be inconsistent, and confusing, if this: class A def thing=(x); end def other; thing = 100; end end were different from this: class A def other; thing = 100; end def thing=(x); end end or from this: class A def blah=(x); end def other; thing = 100; end end As I understand it, the consistency is that, in all cases, the receiver of a method must appear explicitly, unless both of these things are true: (a) the receiver is self; (b) the variable could not be an already-defined local variable, or a local variable in the process of being defined. I think this is the only algorithm that won't cause shifting behavior in cases like the ones above. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav