From: Tom Sawyer Date: 2002-08-10T06:34:32+09:00 Subject: RE: ambiguity between local variable assignment and writter method On Fri, 2002-08-09 at 15:19, Rich Kilmer wrote: > 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) that's not a bad option. this way you could actually use @instance= instead of self.instance= and it would also make for good form. not as "obvious", from the programmer's perspective, as my solution, but it doesn't incur a speed hit. good thinking, rich. does anyone see any problems with this possibility? ~transami