From: senderista@... (Tobin Baker) Date: 2001-11-17T04:28:05+09:00 Subject: [ruby-talk:25621] Re: Class variables Class variables seem to mar the uniformity of the Ruby class model, since they have different behavior from instance variables of class objects ("class instance variables" in Smalltalk, where every subclass has its own copy). Is there a good reason for this, other than giving instance methods an easy way to access variables in the class? Just to make the distinction between these two types of variables clear: class A @@var = "A" @var = "A" end class B < A @@var = "B" @var = "B" end p A.class_eval("@@var") #=> "B" p A.class_eval("@var") #=> "A" "Aleksei Guzev" wrote in message news:... > Why class variables are shared by subclasses? > > class A > @@cv = 3 > def A.ppp > p @@cv > end > end > > A.ppp > > class B < A > def B.t > @@cv = 5 > end > end > > A.ppp > B.t > A.ppp > > class C < A > @@cv = 7 > end > > A.ppp > B.ppp > C.ppp > > Produces > 3 > 3 > 5 > 7 > 7 > 7