Superclass table inheritance


I am trying to find a way to preserve the same class name without having to cut and paste code from one class to another. How do I do something such as:


Inheritance does it nicely:

class A def initalize puts “Initializing class A” end end

class B < A def initialize super puts “Initalizing class B” end end

Hi Ryan,

I was actually looking at using the same class name. I didn't think it was possible but was wondering. In ruby you can override any method as you wish dynamically. So defining class A twice with two initialize functions will not work because the second defined class of the same name will override the first.

Ryan Bigg wrote:

Not quite override, more like extending.

Re-defining a class in Ruby extends that class, but redefining a method on a class will override that method, like what you’re finding out now.

No, there can only be one class by a given name, and it can't derive from itself.

What is your goal?