From: Robert Dober Date: 2006-08-04T05:35:22+09:00 Subject: Re: Creating Classes at runtime ------=_Part_94830_11810529.1154637319135 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/3/06, ara.t.howard@noaa.gov wrote: > > On Fri, 4 Aug 2006, David Stokar wrote: > > > David Stokar wrote: > > it works like this (just copy and paste) > > > > i thought i'd chime in here and point out that the idea of this is flawed: > > if you know the name of the class you want to generate, let's say > 'MyClass', > and you also want to refer to it via the bareword constant MyClass then > you > can simply do > > class MyClass; end > > and later > > class MyClass > def an_added_method > # ... > end > end > > the point being that, unless you are going to __also__ going retrieve you > classes via the string name, as in > > c = const_get 'MyClass' > > obj = c::new > > > not > > c = create_class 'MyClass' > > obj = MyClass.new > > then you do not need to dynamically create classes by name since the name > is > know apriori Hmm but that still leaves the OP's question unanswered, how can I create a named class dynamically. eval "class #{x}; end" myref2class = Object.const_get(x) obviously does the job. ( I agree seems flawed to me too, but OP might have his reasons ) I had a quick look into class.c and it seems that rb_define_class is the only way to define the name of the class object, which would mean that eval is the only way to do the trick. Any opinnions? Cheers Robert > > we can never obtain peace in the outer world until we make peace with > ourselves. > - h.h. the 14th dali lama > > Hmmm your quotes enlighten me (even more than your posts ;) ------=_Part_94830_11810529.1154637319135--