From: Jim Weirich Date: 2006-04-10T04:45:59+09:00 Subject: Re: Dumb reflection problem - create object from String Robert Dober wrote: > On 4/9/06, Brian Parkinson wrote: >> >> 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 s.split('::').inject(Object) { |s,k| s.const_get(k) }.new -- Jim Weirich -- Posted via http://www.ruby-forum.com/.