From: pharrington Date: 2009-12-01T08:45:06+09:00 Subject: Re: Problem trying to get a constant with correct scope On Nov 30, 6:10 pm, Alexandre Mutel wrote: > pharrington wrote: > > On Nov 30, 5:47 pm, Alexandre Mutel wrote: > >> result = lookup_in.const_get sym > >> 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 :\ > > Ok, so that's a bad news... > > Rob wrote: > >Would your DSL rather do something with const_missing instead of > >method_missing? (see Module#const_missing) I suppose that you could > >set A::C::B = A::B > >-Rob > > Nope, because the block I'm trying to evaluate is "A_CONSTANT > some,parameters", so i expect to parse the parameters as well for this > constant. Moreover, the const_missing doesn't solve the issue as i still > have to lookup through parent's modules to get the constant dynamically > as it is performed statically... > > -- > Posted viahttp://www.ruby-forum.com/. If constant lookup is causing a significant impact on your project's performance, mayhaps a good idea would be to create a tree of commonly used constants (whatever that means for your app) for fast lookup?