class A; end
class B < A; @@cv = 1 end
class A; @@cv = 2 end
class A; @@cv end # => 2
class B; @@cv end # => 1 # !> class variable @@cv of A is overridden by B
···
On Tue, Apr 04, 2006 at 01:08:24AM +0900, dblack@wobblini.net wrote:
On Tue, 4 Apr 2006, Marco wrote:
>I'm trying to teach my Parent class how to set variables into its Child
>class; ie
The parent and its children share class variables:
irb(main):001:0> class A; @@var = 2; end
=> 2
irb(main):002:0> class B < A; @@var; end
=> 2
On Tue, Apr 04, 2006 at 01:08:24AM +0900, dblack@wobblini.net wrote:
On Tue, 4 Apr 2006, Marco wrote:
I'm trying to teach my Parent class how to set variables into its Child
class; ie
The parent and its children share class variables:
irb(main):001:0> class A; @@var = 2; end
=> 2
irb(main):002:0> class B < A; @@var; end
=> 2
... depending on the assignment order
class A; end
class B < A; @@cv = 1 end
class A; @@cv = 2 end
class A; @@cv end # => 2
class B; @@cv end # => 1 # !> class variable @@cv of A is overridden by B
I know this happens. I consider this as an error that Ruby does not
detect yet.
Fortunately some things have changed for the better since then:
···
On Tue, Apr 04, 2006 at 08:44:29AM +0900, dblack@wobblini.net wrote:
On Tue, 4 Apr 2006, Mauricio Fernandez wrote:
On Tue, Apr 04, 2006 at 01:08:24AM +0900, dblack@wobblini.net wrote:
On Tue, 4 Apr 2006, Marco wrote:
class A; end
class B < A; @@cv = 1 end
class A; @@cv = 2 end
class A; @@cv end # => 2
class B; @@cv end # => 1 # !> class variable @@cv of A is overridden by B