From: Dick Davies Date: 2004-04-15T06:26:22+09:00 Subject: Re: Interesting Scoping Rules * Dan Doel [0423 20:23]: > This example, at least, makes sense to me. > > class A > @a = "me" # self is the Class object A > class B > puts @a # self is the class object A::B > end > end > > Instance variables are local to the object, and A and A::B aren't the same > object, so why should A::B see the instance variables of A? Similarly: > > class A > @a = "me" # self is the Class object A > class B > @a = "me2" # self is the Class object A::B > def t > puts @a # self is an instance of A::B > end > end > end > > All of those @a's belong to different objects, so it's not so surprising that > they aren't all the same variable. I could see how this would be a little > confusing thinking from a Java inner-class perspective, but instance > variables in Ruby are object based rather than lexically based. Can I just throw in a link to http://www.visibleworkings.com/little-ruby/ - if I'd read Chapter 2 this morning instead of this afternoon, I wouldn't have been so vague.... -- If life is a stage, I want some better lighting. Rasputin :: Jack of All Trades - Master of Nuns