From: "David A. Black" Date: 2005-10-06T04:51:24+09:00 Subject: Re: Module#const_missing redefinition Hi -- On Thu, 6 Oct 2005, El Barto wrote: > I try to redefine #const_missing but it does not behave as I expect. > > def Object.const_missing(sym) > puts "%s.const_missing: %s" % [self, sym] > end > > class Test > def Test.const_missing(sym) > puts "%s.const_missing: %s" % [self, sym] > end > > # OK: Test.const_missing > Bart > end > > Test.new.instance_eval do > # Object.const_missing, why not Test.const_missing? > Bart > end > > Test.module_eval do > # Object.const_missing, why not Test.const_missing? > Bart > end I believe it's because of the pseudo-static way in which constants are resolved. Spotted at parse-time, Bart is assumed to be a constant of Object. If you change the first one to self.class::Bart, and the second one to self::Bart, they will be resolved as Test::Bart. David -- David A. Black dblack@wobblini.net