Help:dynamic inherit from a class

H

Hang Liu

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
 
C

Chris Roos

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
class MySuperClass; end

Class.new(MySuperClass) #=> create anonymous class that inherits from
MySuperClass.
 
V

Vincent Fourmond

Hang said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top