From: Andrew Wagner Date: 2010-08-28T00:48:45+09:00 Subject: Re: Avoiding eval --001636c5bd85a4c2cd048ed00c10 Content-Type: text/plain; charset=UTF-8 Well, sure. That's a good point. But now you're taking 3 times as long as eval, instead of 1/5 the time, according to my tests. On Fri, Aug 27, 2010 at 11:40 AM, Robert Klemme wrote: > On 27.08.2010 17:24, Andrew Wagner wrote: > > If I have a string like "Math", I know I can use const_get to turn it into >> an instance of Class. Awesome. >> >> But what if I have something like "Math::PI". Am I stuck using eval to >> resolve that? >> > > One typical idiom looks like this: > > a_class = str.split('::').inject(Object) {|cl,n| cl.const_get n} > > Cheers > > robert > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > --001636c5bd85a4c2cd048ed00c10--