On Wed, Apr 1, 2009 at 5:09 PM, Rick DeNatale <rick.denatale / gmail.com> 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:
>
>   > camel_cased_word.
> sub(/^::/,'').
> split("::").
> inject(Object) { |scope, name| scope.const_defined?(name) ?
> scope.const_get(name) : scope.const_missing(name) }
>  

The const_missing handling is a nice touch. I'm pinching this :)