From: dblack@... Date: 2006-02-21T11:48:12+09:00 Subject: Re: Class variables and Constants --8323328-2096957794-1140490051=:20928 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-2096957794-1140490051=:20928" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-2096957794-1140490051=:20928 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Tue, 21 Feb 2006, David Vallner wrote: > D=C5=88a Pondelok 20 Febru=C3=A1r 2006 14:50 dblack@wobblini.net nap=C3= =ADsal: > >> I think Matz is planning to change class variables in 2.0 so that they >> are class/module scoped rather than hierarchy scoped. Meanwhile, >> here's another fun variant: >> >> class A >> end >> >> class B < A >> @@var =3D 10 >> def self.var >> @@var >> end >> end >> >> class A >> @@var =3D 20 >> def self.var >> @@var >> end >> end >> >> p A.var >> p B.var >> > > Oh dear. I do hope the change gets into 2.0, I can't wait for Java trolls= to > ramble against it... > > (Now don't tell anyone, but I have a hunch class instance variables actua= lly > work like you'd expect in this case. I think.) Basically a "class instance variable" is no different from any other instance variable -- it just happens to belong to a class object. The phrase has become commonplace, I guess, because it's sort of unclear otherwise, when you talk about, say, "a class's instance variables", whether you mean the class object's or the ones it is responsible for providing for its own instances. Anyway, instance variables of class objects do, indeed, provide per-class (i.e., per-object-that-happens-to-be-a-class) state, which class variables don't. I think the 2.0 change is going to be that class variables will be like instance variables of a class, except that they will be visible inside the class's instance methods. David --=20 David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black --8323328-2096957794-1140490051=:20928-- --8323328-2096957794-1140490051=:20928--