From: Dan Doel Date: 2003-08-22T02:23:31+09:00 Subject: Re: Class variables - a surprising result Gawnsoft wrote: >A class-instance variable is one in which the scope is specific to a >given (sub)class. > >Am I correct in dimly recalling that Ruby has support for >class-instance variables? > You are correct. If you search the ruby-talk archives you'll find a discussion almost the same as this one. Bottom line was that you have to do something like this: class Foo def initialize class << Foo @class_instance_var = 'c' end end def test class << Foo puts @class_instance_var end end end class Bar < Foo def initialize class << Bar @class_instance_var = 55 end end def inc class << Bar @class_instance_var += 1 end end def test class << Bar puts @class_instance_var end end end foo1 = Foo.new bar1 = Bar.new bar2 = Bar.new foo1.test bar1.test bar2.test bar1.inc bar1.test bar2.test This prints: c 55 55 56 56