[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Attempted roadmap of future instance variables....

Steve Tuckner

12/2/2003 6:10:00 PM

OK so the jist of it is that @_var variables are stored with the class of
the instance but the class has no access to that. That is all. Right?

Steve Tuckner

> -----Original Message-----
> From: Lyle Johnson [mailto:lyle@users.sourceforge.net]
> Sent: Tuesday, December 02, 2003 11:57 AM
> To: ruby-talk ML
> Subject: Re: Attempted roadmap of future instance variables....
>
>
> Steve Tuckner wrote:
>
> > So @_var does not refer to the class instance variable @var?
>
> Correct. @_var and @var refer to two *different* instance variables.
>
> > If @_var defined in a class context is different from @_var
> in an instance then how
> > does one refer to the @_var created in the instance context
> in the class
> > context?
>
> If I parsed that question correctly, the answer is "you don't" ;)
>
> Generally speaking, there isn't any way for the *class* of an
> instance
> to refer to its instance's instance variables.
>
> > I would think that @_var in the instance context should be
> the same as
> > refering to the @var in the class context. It would be like having
> > attr_accessor for @var with a little sugar for the instance context.
>
> I'm not sure, but I think you may be under the impression
> that @_var and
> @var are somehow linked to each other, and they aren't.
> (Perhaps David
> should have used completely different names in the original example).
>
> For C++ programmers, the easiest way to think of this is that a Ruby
> instance variable whose name starts with an underscore (such
> as @_foo)
> is private, in the C++ sense. An instance variable whose name doesn't
> start with an underscore (such as @bar) is protected, again
> in the C++
> sense.
>
> Unless, of course, I am completely confused ;)
>

1 Answer

matz

12/2/2003 6:20:00 PM

0

Hi,

In message "Re: Attempted roadmap of future instance variables...."
on 03/12/03, Steve Tuckner <STUCKNER@MULTITECH.COM> writes:

|OK so the jist of it is that @_var variables are stored with the class of
|the instance but the class has no access to that. That is all. Right?

No. @_var variables are stored in the instance, but they are
accessible only from methods defined in the same class.

matz.