From: ara.t.howard@... Date: 2006-04-04T00:58:40+09:00 Subject: Re: Setting class variable from parent class? On Tue, 4 Apr 2006, Marco wrote: > Hi All! > > I'm trying to teach my Parent class how to set variables into its Child > class; ie > > class Parent > def self.set_my_class_variable(value) > reference_to_my_class.my_variable = value > end > end > > class Child > set_my_class_variable "hello world" > end > > I think what I'm missing is the way to reference the Child class. I've > been wrongly supposing that > > Parent.set_my_class_variable(value) > @@my_variable = value > end > > would be doing the work. But the '@@' syntax sets the class variable to > Parent. > > Thank you, > Marco harp:~ > cat a.rb class Parent class << self attr_accessor 'a' def inherited child child.a = 42 end end end class Child < Parent end p Child.a harp:~ > ruby a.rb 42 hth. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama