From: Paul Duncan Date: 2006-09-03T05:19:01+09:00 Subject: Re: How can I do this without eval... --GyRA7555PLgSTuth Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * J2M (james2mccarthy@gmail.com) wrote: >=20 > Jan Svitok wrote: >=20 > > model =3D const_get(model_name.to_s.capitalize) This might be more appropriate: model_class =3D const_get(model_name.to_s.classify) Classify will take care of things that capitalize misses, like underscores and extraneous plurals. Take a look at the following output: # test strings and test methods strings =3D %w{blog_post layers magazine_subscribers} methods =3D %w{capitalize classify}.map { |m| m.intern } # iterate over test strings and handle each one puts strings.map { |str| "'#{str}'\n" << methods.map { |meth|=20 " #{meth}:\t'#{str.send(meth)}'"=20 }.join("\n") } Produces the following: 'blog_post' capitalize: 'Blog_post' classify: 'BlogPost' 'layers' capitalize: 'Layers' classify: 'Layer' 'magazine_subscribers' capitalize: 'Magazine_subscribers' classify: 'MagazineSubscriber' Hope that helps... --=20 Paul Duncan pabs in #ruby-lang (OPN IRC) http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562 --GyRA7555PLgSTuth Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFE+ecczdlT34LClWIRAnSXAJ9tlpxaaTBSuUugQDptEXUtoKK79QCfTrkf 09ZARqbi2tjeZ7Eur94AtoI= =3rEl -----END PGP SIGNATURE----- --GyRA7555PLgSTuth--