From: Ross Bamford Date: 2005-11-27T09:32:27+09:00 Subject: Re: Nubish questions about syntax and gems On Sat, 26 Nov 2005 21:44:00 -0000, David A. Black wrote: > What you've got basically is: > > class A > @@foo = "A's class variable foo" > end > @@foo = "Object's class variable foo" > class B > @@foo = "B's class variable foo" > end > > Since B is a subclass of Object, setting B's @@foo also sets Object's > @@foo. The reason A's @@foo (when you see it via the instance eval) > does not change is that if you create a subclass's class variable > *first*, and then the superclass's (in this case, A and Object, > respectively), they are separate: > > irb(main):002:0> class A; end; class B < A; @@foo = 1; end; class A; > @@foo = 2; puts @@foo; end > 2 > => nil > irb(main):003:0> class B; puts @@foo; end > 1 >David That's pretty subtle. Definitely one for the notebook. Cheers, -- Ross Bamford - rosco@roscopeco.remove.co.uk