From: Paul Duncan Date: 2002-12-27T06:38:54+09:00 Subject: Re: String#to_class? --rwgQ89ZNnFUwFHTC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Tim Bates (tim@bates.id.au) 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 o= f 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"? Hey, I wrote a String#to_class implementation using const_get for my friend a few months back. Check out http://www.pablotron.org/download/string_to_class.rb (there's test code and examples included in the file). > Tim Bates > --=20 > tim@bates.id.au >=20 --=20 Paul Duncan pabs in #gah (OPN IRC) http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562 --rwgQ89ZNnFUwFHTC Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+C3bqzdlT34LClWIRApBOAJwOEOy9IZv6unJdazWIWeLCSbRWDACcCCl1 Nc/Ho4W7+4Uirrq/Xzfm9fM= =a+k8 -----END PGP SIGNATURE----- --rwgQ89ZNnFUwFHTC--