From: Alexandre Mutel Date: 2009-12-01T07:35:14+09:00 Subject: Re: Problem trying to get a constant with correct scope pharrington wrote: > On Nov 30, 4:15�pm, Alexandre Mutel wrote: >> How to get constant B from inside C but executed from outside first >> declaration? >> After module A is declared, trying : >> >> >>> puts A::C.class_eval("B") >> >> failed and const_get is not working too. > Your goal is confusing. module A contains the "B" constant, not class > C. How does "A::B" not satisfy your needs? What exactly are you trying > to do? Sorry for the shortcut in my explanation. In fact, my test case is a bit more dynamic. I'm developing a DSL that evaluate blocks that can contain a line like this: A_CONSTANT some,args,...etc. So i'm trying to get the constant dynamically and not statically : I have something like : class ConstSearcher def self.method_missing(sym,*args) puts const_get(sym) end end module A class B end class C < ConstSearcher puts B # << static constant lookup is working end end But performing a dynamic lookup is not : A::C.instance_eval("B 11111") : NameError: (irb):3:in `const_get': uninitialized constant A::C::B from (irb):13 from (irb):3:in `method_missing' from (eval):1 from :0 i tried several methods (eval with binding...etc.) without any success. Does i have to loop through parent modules and perform a const_get on each module ? (generating a huge performance penalty). -- Posted via http://www.ruby-forum.com/.