From: Joel VanderWerf Date: 2004-11-12T04:42:36+09:00 Subject: Re: automatically call function on attribute set Joe Van Dyk wrote: > Joel VanderWerf wrote: > >> def fly >> self.x += 1 # don't use @x=, or else no >> notification end >> end >> > > > What is the difference between self.x and @x? In ruby, assigning to an instance variable @x like @x += 1 does not invoke any methods (except the + method of the Integer class, in this case). So there's no way for the Airplane class to detect the assignment and (in this case) notify observers. By contrast, the code self.x += 1 forces a call to the method "x=", which has been defined by "observable :x" to both set the value of @x and to notify observers. And just for completeness, the code x += 1 can only assign to a local variable, even if "x=" has been defined as a method.