Hi --

On Mon, 20 Feb 2006, Tony Mobily wrote:

> Hi,
>
>
>> Have you tried this?
>>
>>   class A
>>     @@var = 10
>>     def self.var
>>       @@var
>>     end
>>   end
>>
>>   class B < A
>>     @@var = 20
>>   end
>>
>>   p A.var
>> 
>> :-)
>
> AAAAAAAHHHHHHHHH!!!!!!!!!!!!
> I've been playing with this the whole night. I am not gonna stop until I've 
> finished writing a clear document that explains absolutely everything.

I think Matz is planning to change class variables in 2.0 so that they
are class/module scoped rather than hierarchy scoped.  Meanwhile,
here's another fun variant:

class A
end

class B < A
   @@var = 10
   def self.var
     @@var
   end
end

class A
   @@var = 20
   def self.var
     @@var
   end
end

p A.var
p B.var


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black