From: Bill Atkins Date: 2005-04-19T12:24:28+09:00 Subject: Re: Dynamic object construction ------=_Part_346_25718566.1113881046339 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If class is a a class name (a String): @obj =3D Object.const_get(klass).new Using "class" as a parameter name won't work - the standard is to use=20 "klass" instead. Bill On 4/18/05, John Lam wrote: >=20 > I'm trying to create a new object where the class of the object is > parameterized. My current solution is to use eval(): >=20 > def create(class) >=20 > @obj =3D eval("#{class}.new()") >=20 > end >=20 > Is there a better way of doing this to avoid the hit of eval()? >=20 > Thanks, >=20 > -John >=20 > http://www.iunknown.com >=20 >=20 --=20 Bill Atkins ------=_Part_346_25718566.1113881046339--