------art_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 <parkI / whatevernot.com> 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 = Module
s.split(%r{::|\.}).each do
    |name|
    m = 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óŐise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

------art_36720_11343853.1144610506841--