Hi all:
Now I have problem about dynamiclly inheriting form a class.
For example:
class_name=‘MyClass’
klass = Object.const_set(class_name, Class.new)
klass.class_eval do
…
end
now i get a class named 'MyClass',then i want the MyClass inherit
from another
class ‘AnotherClass’,how can I do it?
On 10/19/06, Hang L. [email protected] wrote:
now i get a class named 'MyClass',then i want the MyClass inherit
from another
class ‘AnotherClass’,how can I do it?
class MySuperClass; end
Class.new(MySuperClass) #=> create anonymous class that inherits from
MySuperClass.
Hang L. wrote:
now i get a class named 'MyClass',then i want the MyClass inherit
from another
class ‘AnotherClass’,how can I do it?
Use the optionnal parameter of Class.new:
------------------------------------------------------------- Class::new
Class.new(super_class=Object) => a_class
Creates a new anonymous (unnamed) class with the given superclass
(or Object if no parameter is given). You can give a class a name
by assigning the class object to a constant.
Cheers !
Vince