From: Sean O'Halpin Date: 2009-04-02T01:31:12+09:00 Subject: Re: Anything better than klass = eval("#{task_class}") On Wed, Apr 1, 2009 at 5:09 PM, Rick DeNatale wrote: > > Actually, I don't think this is entirely right, since const_get will find > constants found in outer scopes. > > For example constantize("MyModule::Object") would return ::Object > > So a little better would be: > >  def constantize(camel_cased_word) >   camel_cased_word. >     sub(/^::/,''). >     split("::"). >     inject(Object) { |scope, name| scope.const_defined?(name) ? > scope.const_get(name) : scope.const_missing(name) } >  end The const_missing handling is a nice touch. I'm pinching this :)