From: "T. Onoma" Date: 2003-12-17T07:40:02+09:00 Subject: Re: Copying methods from one class to another On Tuesday 16 December 2003 10:51 pm, Hacksaw wrote: > > No. Why would B and C be equal? B is a subclass of C. Specifically, methods > and variable defined in B are not reflected in C. > > The only way that they are equal is that an inherited method in B should do > the same thing as in C. Same with inherited variables. That's okay, I had the same difficulties understanding this at firs too. Let back up a bit. Look at this: A = "1" B = "2" A = B What happens? p A # => "2" It's the same thing for classes. I know it's tempting to "over think" when classes are being delt with, I did the very same thing before I understood what was going on. But it really is that simple. After all, classes are objects just like strings. So lets do it again, but this time with less "syntatical sugar": A = Class.new B = Class.new(A) # A is the superclass of B A = B All that's happened is that A no longer points to its former self. Rather it now points to the same thing B does. The old A still exists as the superclass of B, but we no longer have a convienent constant to reference it by. Note that constants in Ruby are rather variable. The only thing that is noticably different is that Ruby spits out a warning saying we have redefined a constant. So, the short notation of class A < A is the same as: A = Class.new(A) and does the exact same thing as above, except that it dispenses with the go between constant B. And is analogous to doing this with a string: str = " A new string " + str -- T.