From: Paul Duncan Date: 2002-12-27T06:47:07+09:00 Subject: Re: String#to_class? --6K2R/cS9K4qvcBNq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Dave Thomas (dave@pragprog.com) wrote: > On Sat, 2002-12-21 at 03:00, Tim Bates wrote: > > I have a class being used in a unit test: > >=20 > > TC_Foo > >=20 > > I match it against a regexp: > >=20 > > /TC_(.*)/.match(self.class.name) > >=20 > > I end up with a string ($1 =3D=3D "Foo") which I want to be an instance= of Class=20 > > (=3D=3D Foo). How can I convert a String to a Class? Will I have to use= =20 > > ObjectSpace to find a Class whose Class#name =3D=3D "Foo"? >=20 >=20 > There's a page on the Wiki with a number of solutions: >=20 > http://www.rubygarden.org/ruby?FindClassesByName I don't know if the original poster needs it, but The examples there don't work with anonymous classes or non-colon delimited class names. The bit I wrote does. > Cheers >=20 >=20 > Dave >=20 >=20 --=20 Paul Duncan pabs in #gah (OPN IRC) http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562 --6K2R/cS9K4qvcBNq Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+C3jYzdlT34LClWIRAvhgAKDXjq8Bg/sAS3c7ieTPxfFHQkvSIwCgu1lf 3w0VmbfNHcmX1AtiaLfjIEI= =fo61 -----END PGP SIGNATURE----- --6K2R/cS9K4qvcBNq--