Help:dynamic inherit from a class

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?

--
Posted via http://www.ruby-forum.com/.

class MySuperClass; end

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

···

On 10/19/06, Hang Liu <liuhang1113@gmail.com> wrote:

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?

Hang Liu wrote:

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?

  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