# Class variables are still inherited?

**URL:** <https://www.ruby-forum.com/t/class-variables-are-still-inherited/160919>\
**Category:** Ruby\
**Created:** [February 20, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/class-variables-are-still-inherited/160919 "2009-02-20T22:55:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hut](https://www.ruby-forum.com/u/hut)\
**Post date:** [February 20, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/class-variables-are-still-inherited/160919/1 "2009-02-20T22:55:40Z")

</div>

Hi ruby-talk

It’s said everywhere that class variables are not inherited anymore in  
newer versions of ruby. I experience a different behaviour, can you give  
me any hints about what I’m doing wrong?

class Foo  
@@a = 1  
def self.moo() @@a end  
end

class Bar \< Foo  
@@a = 2  
end

Foo.moo == Bar.moo # both are 2

My ruby comes from this package: ruby-1.9.1-p0.tar.bz2

---

<div class="post-metadata">

**Author:** ![hut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hut](https://www.ruby-forum.com/u/hut)\
**Post date:** [February 20, 2009, 11:11pm UTC](https://www.ruby-forum.com/t/class-variables-are-still-inherited/160919/2 "2009-02-20T23:11:01Z")

</div>

Hi –

On Sat, 21 Feb 2009, hut wrote:

> class Bar \< Foo  
> @@a = 2  
> end
> 
> Foo.moo == Bar.moo # both are 2
> 
> My ruby comes from this package: ruby-1.9.1-p0.tar.bz2

For a while there was a change so that they weren’t shared in the  
whole hierarchy, but it got reverted.

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Coming in 2009: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))

Ruby Training Atlanta! April 1-3, [ruby training, atlanta, april 2009 - entp](http://www.entp.com/training/atlanta09)
