From: PsiPro Date: 2011-03-26T00:30:26+09:00 Subject: Re: Dynamic classes On Mar 25, 10:21 am, PsiPro wrote: > So I am working on some metaprograming and have some questions about > how to get what I need out of dynamic classes. > > Right now I know I can define dynamic classes like so: > a) TestClass = Class.new > b) var_class = Class.new > > These work as expected but I need the functionality provided by case > A. Specifically I need to have the instances respond to .class > appropriately. .class for case B returns Class, while case A responds > TestClass > > The reason I need to do this is that I want to dynamically generate > classes, including their names. How can I accomplish this? > > My desired results: > > variable = Class.new > variable.class.name == 'variable' > > OR, I need to be able to assign a dynamic constant name (I know I > know). > > Any help would be appreciated. So I figured it out on my own, but still need some feedback. Running x="Foo" c = eval("ClassNamePrefix#{x} = Class.new") provided the desired results. I don't like the idea of using eval if at all possible tho, any feedback would be greatly appreciated. Thank you.