So I see…
— begin classvar.rb —
@@name = "I’m the parent."
class Son < Parent
@@name = "I’m the son."
class Daughter < Parent
@@name = "I’m the daughter."
Son.new # => I’m the daughter.
Daughter.new # => I’m the daughter.
— end —
This behavior is downright counterintuitive to me. The class
"Daughter" has managed to affect the behavior of the class “Son”, but
"Daughter" is not an ancestor of “Son”.
What would you guys suggest I do if I want a variable set in the
parent that the child may or may not override? So far, I’ve had to
resort to using instance variables instead, like this:
@name = "I’m the parent."
@name = "I’m the son."
@name = "I’m the daughter."
This doesn’t seem to be the right way to do things though, since with
the way I’m using @name, it’s a variable whose value will be the same
across all instances of the same class.
On Mon, Aug 12, 2002 at 02:05:45AM +0900, Kent Dahl wrote:
Because class variables are some kind of wierd black magic. Once a class
variable comes into existance, it is available to all instances of the
class and subclasses. I.e. it is available downwards in the inheritance
When you don’t make the @@data variable until the subclass, it does not
propagate back up to the superclass. Beware, this path may lead to