From: Rich Kilmer Date: 2002-08-10T06:19:25+09:00 Subject: RE: ambiguity between local variable assignment and writter method How about: class Person def initialize(name, age) @name = name # calls name=(name) if self.name= exists @age = age # set @age because not self.age= end def name=(name) raise "Name needs to be String!" unless name.kind_of? String @name = name # sets @name because in scope of name= end end You change the behavior of @var=value to call the self.var= method if it exists unless you are in the self.var= method, then you set the var. It would only effect performance of @var= (or @var for reader) -rich > -----Original Message----- > From: Mathieu Bouchard [mailto:matju@sympatico.ca] > Sent: Friday, August 09, 2002 4:47 PM > To: ruby-talk ML > Subject: Re: ambiguity between local variable assignment and writter > method > > > On Sat, 10 Aug 2002, Tom Sawyer wrote: > > why couldn't ruby just check to see if there was such a setter method > > first, prior to assuming it a local variable assignment? the only > > consequence of this would be that you could not use local variable names > > identical to your method names. something i tend to do anyway. > > Because of the wild ways in which Ruby can do inheritance > (<,<<,#include,#extend) and delegation (#method_missing), methods may pop > up in unplanned spots. Your feature causes a leakage of influence between > the local namespaces and the method namespaces, which is highly > undesirable semantically ("hairy"), in addition of really slowing things > down. > > ________________________________________________________________ > Mathieu Bouchard http://artengine.ca/matju >