From: "Eustáquio Rangel de Oliveira Jr." Date: 2005-07-04T04:36:47+09:00 Subject: Re: class variable leading a double life Hey Robert. :-) > I'm not sure about "more clear" with your example... :-) Me neither, to be honest ehehe. :-) > In fact you have v2, v2 and v3 which shows a bit unfortunate naming > because these are three different things. They are all instance > variables only that the first v2 is an instance variable of the class > object while the second v2 is an instance variable of each Test > instance. These are not the same nor do they interfere with each other. Uhnnn that's because of was declared on the class body and other on the method, right? So to access the first one, only with a class method, right? > Yes. And you can create them even later. Instance variables can spring > into existing any time Not just created on initialize so. But what is the difference about a @@var class variable and a instance variable of the class? Since @@ at least should be let me say, "unique" (or static perhaps) it's not the same kind of behaviour of a @var defined on the class body? I mean, seems that they are on the same place. >> Kind of >> +-------+ +-----+ >>>| Test +-----+ t | >> +-------+ +-----+ >> + | >>>| @@v1? | | @v3 | >>>| @v2? | +-----+ >> +-------+ > > You're missing @v2 in the right object. And the right object for a class body defined @v2 is ... (fill please eheh). :-) >> gives me that error, so there is also a scope difference on a constant >> like MaxTime and a variable like @maxtime, defined on the class body? > > The trick is in the lookup: @something always refers to the current > instance at the moment of execution. Your instance method isTooLong > (which btw. in Ruby convention would be named too_long?) I just copied the Dave Thomas example. :-) > refers to a > @maxtime instance variable of the SongList2 instance - as these > instances don't have a @maxtime you get nil. Mmmm right. > Constants are looked up via in class scope - naturally because you > cannot have constances in an instance. Now I got the constant stuff. :-) Thanks! ---------------------------- Eust�quio "TaQ" Rangel eustaquiorangel@yahoo.com http://beam.to/taq Usu�rio GNU/Linux no. 224050