Hello --

I've been puzzling over Ruby's treatment of class variables -- not so
much the "what" as the "why".

It seems strange to me that a class somewhere off in one side of an
inheritance tree can affect a class variable all over the tree.

For illustration purposes (no claims of greatness of design):

   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 seem to be not so much per class as per class
hierarchy or family.  I can't quite figure out why they work this way,
rather than working like instance methods (so that redefinition in a
child class stops the search process up the inheritance path).

Insights, opinions, and/or words of wisdom welcome.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav