From: Alexandre Mutel Date: 2009-12-02T03:32:47+09:00 Subject: Re: Ruby should support consistent constant lookup (and dynamic) Walton Hoops wrote: > irb(main):012:0> A::B.foo do > irb(main):013:1* puts eval('BAR') > irb(main):014:1> end > 1 > => nil > > Done. A more experienced Rubist may be able to do it without eval, but > that works. Oh, thanks, at least the eval is working on constants with 1.9, this is good to know. > >> Should'nt this constant lookup be consistent between static and >> const_get? > > No, that's not what const_get is for. It's operating on a class > not a scope. That's why it's an instance method. The way you > calling it is literally equivalent too: > > A::B.const_get(:BAR) > > In other words, you are asking for _B's_ constants. Since B, > nor any of its ancestors have the constant BAR, an error occurs. I understand the current const_get behavior, but still, it would be nice to have something equivalent to fully resolving a constant in a faster way without going through the eval way. I was thinking about a const_get with an aditionnal parameter like def const_get(symbol, check_module_hierarchy=false) {}, still living this method in the module. -- Posted via http://www.ruby-forum.com/.