From: noreply@... Date: 2007-04-16T17:02:35+09:00 Subject: [ ruby-Bugs-8156 ] class variables and inheritance Bugs item #8156, was opened at 2007-01-25 23:05 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=8156&group_id=426 Category: Core Group: 1.8.4 Status: Open Resolution: None Priority: 3 Submitted By: Lance Ivy (cainlevy) Assigned to: Nobody (None) Summary: class variables and inheritance Initial Comment: The unexpected behavior is shown in this script: --------------- #!/usr/bin/ruby class A def self.foo @@foo end def self.foo=(val) @@foo = val end end class B < A; end class C < A; end A.foo = 'a' B.foo = 'b' C.foo = 'c' puts A.foo puts B.foo puts C.foo --------------- When I run this, I expect to see: a b c But instead I see: c c c ---------------------------------------------------------------------- Comment By: Adam Bozanich (abozanich) Date: 2007-04-16 08:02 Message: Why would you expect that? you can do what you want like so: class A class << self def foo @foo end def foo=(val) @foo = val end end end class B < A ; end class C < A ; end A.foo = 'a' B.foo = 'b' C.foo = 'c' puts A.foo , B.foo , C.foo ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=8156&group_id=426