> Suppose that you run this code:

Ruby 1.7.1

> class Sub
>    def foo
>      "SUB foo!"
>    end
> end
> 
> class Super
>    def foo
>      "SUPER foo!"
>    end
> end

s = Sub

> # note: redefining Sub
> class Sub < Super
>    def bar
>      "bar!"
>    end
> end

s.new.foo()    => "SUB foo!"
Sub.new.foo()  => "SUPER foo!"

> You get a "warning: already initialized constant Sub", which seems fine. 
> Question: when you do "Sub.new.foo", which foo do you get? I expected 
> Super's - that the new version of Sub would wipe out the old. I was 
> surprised that you got neither. foo is not a method Sub responds
> to. (bar is.)

I get Super, because the new Sub inherits from (the old) Super.
As you notice by my trick with s, you actually have two classes, but
one of them is no longer referenced by a Constant.

> I'm not sure my expected behavior is correct. The second "class Sub" might 
> instead add a method "bar" to the exiting "foo" and link Super into the 
> inheritance chain of Sub. But eliminating "foo" seems odd.
> 
> Ruby 1.6.3
> 
> Is there a way to destroy the old definition of Sub before the second 
> "class Sub"? I'm writing text that explains inheritance, and it's awkward 
> to say "if you're following along with IRB, be sure to exit your
> session now."

Don't suppose you have to say this; Don't know of a method to destroy
a class.

+--- Kero ------------------------------ kero / chello.nl ---+
|  Don't split your mentality without thinking twice       |
|                          Proud like a God -- Guano Apes  |
+--- M38c ------- http://members.chello.nl/~k.vangelder ---+