Philip Mak wrote:
> 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".

The fact that you define the classvariable in Parent suggest that _all_
subclasses of Parent should have access to one and the same variable.
There is no way for Ruby to know wheter you want to make your own class
variable or reuse the parents when you simply assign to it.

 
> What would you guys suggest I do if I want a variable set in the
> parent that the child may or may not override? 

I take it you mean that the overriding change should only propagate
downwards, as if you had defined the class variable at that particual
subclass?

Depending on what you wish to do with the variable, I'd suggest:
- Make a separate class variable in the subclasses that is assigned the
variable of the parents class variable to start with:
  class Son < Dad
    @@son_data = @@data
    # use @@son_data only
  end
- Use instance methods. Instance methods are made for overriding, class
variables not so. 
- Use real class instance variables instead of class variables. (Might
be hard to do if you still want to propagate the variables downwards,
since a subclass is a totally different object.)

But it really depends alot on what you want to be able to do with the
variable.

-- 
(\[ Kent Dahl ]/)_    _~_    __[ http://www.stud.ntnu.no/~kentda/ ]___/~
 ))\_student_/((  \__d L b__/  NTNU - graduate engineering - 5. year  )
( \__\_/__/ ) _)Industrial economics and technological management(
 \____/_\____/ (____engineering.discipline_=_Computer::Technology___)