From: Robert Dober Date: 2006-04-10T04:21:52+09:00 Subject: Re: Dumb reflection problem - create object from String ------=_Part_36720_11343853.1144610506841 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 4/9/06, Brian Parkinson wrote: > > Sven Klemm wrote: > > [deletia] > > > Module.const_get(s).new > > Thanks! > > I knew it would be a one-liner. :-) > > parki... I am afraid that the only one-liner is eval :( suppose s contains the name of your class Module.const_get s does not work unless your class is defined on top level. In oder to have the *same* semantics as eval(s).new we have to write m =3D Module s.split(%r{::|\.}).each do |name| m =3D m.const_get(name) end m.new I suggest to look at ObjectSpace for another alternative, hardly more efficent though :( Robert -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_36720_11343853.1144610506841--