From: Arlen Cuss Date: 2012-10-24T19:31:05+09:00 Subject: Re: Dynamically creating subclasses Hi Sun, How about this? 1.9.3p194 :001 > class A; def initialize; puts "new A"; end; end => nil 1.9.3p194 :003 > name = "X" => "X" 1.9.3p194 :007 > Object.const_set name, Class.new(A) => X 1.9.3p194 :008 > X => X 1.9.3p194 :009 > X.new new A => # 1.9.3p194 :010 > On Wednesday, 24 October 2012 at 9:25 PM, The Sun wrote: > Hi, > > I have to dynamically create a number of classes with different names. > All of them have to inherit from the same subclass. > > I tried the following: > > eval(class myName < ParentClass; end) where myName is a String > dynamically set together > or the same without eval. > > In fact i succeeded in creating objects of the new classes (myName.new) > and the name seems to be set right, but the instantiation does not call > the parents constructor. > > Can you point to my mistake? > > Thanks > sun > > -- > Posted via http://www.ruby-forum.com/.