Class variables are still inherited?

H

hut

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
 
D

David A. Black

Hi --

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

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
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

Ruby Training Atlanta! April 1-3, http://www.entp.com/training/atlanta09
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top