You can give it a dynamic name with eval:

ruby-1.9.2-p180 > a =3D "Monkey"
 =3D> "Monkey"=20
ruby-1.9.2-p180 > eval("#{a} =3D Class.new")
 =3D> Monkey=20
ruby-1.9.2-p180 > b =3D Monkey.new
 =3D> #<Monkey:0x00000100b37f80>=20
ruby-1.9.2-p180 >=20

It seemed a bit messy so I checked out also Class.new, Module.new and =
Module.name ( class inherits from module and hence uses the name =
property) but no luck :-(

I wonder whyClass.new and Module.new don't have a parameter to define =
the name (seems something a person would want to do).  Any ideas ?=20

Regards,
V.


On Mar 25, 2011, at 3:25 PM, PsiPro wrote:

> So I am working on some metaprograming and have some questions about
> how to get what I need out of dynamic classes.
>=20
> Right now I know I can define dynamic classes like so:
> a) TestClass =3D Class.new
> b) var_class =3D Class.new
>=20
> 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
>=20
> The reason I need to do this is that I want to dynamically generate
> classes, including their names. How can I accomplish this?
>=20
> My desired results:
>=20
> variable =3D Class.new
> variable.class.name =3D=3D 'variable'
>=20
> OR, I need to be able to assign a dynamic constant name (I know I
> know).
>=20
> Any help would be appreciated.
>=20