At Sun, 11 Mar 2001 13:44:17 +0100 Kent Dahl wrote:

> Max Ischenko wrote:
>> class A
>>         @@VAR = {'A'=>1}
>> 
>>         def initialize
>>                 puts @@VAR
>>         end
>> end
>> 
>> class C < A
>>         @@VAR = {'C'=>1}
>> end
>> 
>> class B < A
>>         @@VAR = {'B'=>1}
>> end

> From your expectations, you're basically  assuming that each class has its
> own  set of  variables,  that  aren't touched  by  subclasses. That  isn't
So, this is a feature? It seems counter-intuitive.

Here is excerpt for Dave Tomas' book:
Class Variables

A class  variable is shared  among all  objects of a  class, and it  is also
accessible to the class methods that we'll describe later. There is only one
copy of a particular class variable  for a given class. Class variable names
start with two ``at'' signs, such as ``@@count''. Unlike global and instance
variables, class variables  must be initialized before they  are used. Often
this initialization  is just a  simple assignment in  the body of  the class
definition.

It says 'one copy for a given class' not for `class hieararchy'.

> exactly how it goes  in Ruby (nor in Java for that  matter). The fact that
> the  last @@VAR  is  the one  kept,  is  mearly because  every  line is  a
> statement in Ruby.


> How about this case?

[ code cut; thanks ]

-- 
"He don't know me vewy well, DO he?"   -- Bugs Bunny