On Wed, 2002-10-30 at 17:38, William Djaja Tjokroaminata wrote:
> dblack / candle.superlink.net wrote:
> 
> > I don't think one should make that assumption; it's awfully rigid.  I
> > might have:
> 
> >   def stuff=(x)
> >     @thing = x
> >   end
> 
> >   def stuff
> >     @thing
> >   end
> 
> > which is a dinky example at best... but meaning there is no necessary
> > connection between the methods and the implementation.
> 
> 
> Well, it looks like a contrieved example, so it is really a matter of
> personal style/convention.  But now suppose that someone really writes a
> code like above in a class, and I want to derive a new class from it, and
> I need to access "the object logically represented by
> stuff/thing".  In my derived class, should I use "@thing" or should I use
> "self.stuff"?

Definitely use self.stuff to avoid breaking encapsulation.

Imagine if the class was instead:

  def stuff=(x)
     @thing = x + 1
  end
 
  def stuff
     @thing - 1
  end


Using @thing as a synonym for self.stuff would give the wrong result.

-- 
Dr. Nathaniel Pryce, Technical Director, B13media Ltd.
Studio 3a, 22-24 Highbury Grove, London N5 2EA, UK
http://www.b13media.com