From: pharrington Date: 2009-12-01T08:00:15+09:00 Subject: Re: Problem trying to get a constant with correct scope On Nov 30, 5:47 pm, Alexandre Mutel wrote: > Currently, i'm using something like > > class Module >   def dyn_const_get(sym) >     list = name.split('::').inject([Object]) {|hierarchy,name| hierarchy > << hierarchy.last.const_get(name)} >     result = nil >     while !list.empty? && result.nil? >       begin >         lookup_in = list.pop >         result = lookup_in.const_get sym >       rescue >       end >     end >     result >   end > end > > And performing : A::C.dyn_const_get(:B) returns > A::B > > But that's a very bad option in terms of performance... I'm wondering if > there are any other options? > -- > Posted viahttp://www.ruby-forum.com/. As far as I know the only way to do this is to traverse the inheritance hierarchy :\