On Fri, Aug 27, 2010 at 10:40 AM, Robert Klemme
<shortcutter / googlemail.com>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/
>
>
Here is how Rails implements Robert's suggestion:

(see method constantize)
http://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb