From: Lyle Johnson Date: 2003-12-03T02:57:08+09:00 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 ;)