From: matz@... (Yukihiro Matsumoto) Date: 2001-08-12T00:07:02+09:00 Subject: [ruby-talk:19535] Re: the way class variables work Hi, In message "[ruby-talk:19506] the way class variables work" on 01/08/11, David Alan Black writes: | class Vehicle | @@tires = 0 | def tire_count | @@tires | end | end | | class Car < Vehicle | @@tires = 4 | end | | class Bike < Vehicle | @@tires = 2 | end | | puts Car.new.tire_count # => 2 Class variables are to share value among classes/modules and its instances. If you want to have per class information, you have class instance variable, or constants. class instance variables class Vehicle @tires = 0 def Vehicle::tire_count @tires end def tire_count type::tire_count end end class Car < Vehicle @tires = 4 end class Bike < Vehicle @tires = 2 end puts Car.new.tire_count # => 4 constants class Vehicle def tire_count type::TIRES end end class Car < Vehicle TIRES = 4 end class Bike < Vehicle TIRES = 2 end puts Car.new.tire_count # => 4 class variables are global variables with limited scope (to specific class hierarchy), so I do not recommend to abuse them. matz.