From: nobuyoshi nakada Date: 2005-11-16T14:34:15+09:00 Subject: Re: The subtleties of const_missing Hi, At Wed, 16 Nov 2005 13:36:46 +0900, Nicholas Seckar wrote in [ruby-talk:165996]: > I've run into an issue regarding the use of const_missing. This issue > revolves around the fact that these two cases are supposed to behave > differently from each other: > > irb(main):001:0> B = 10 > irb(main):002:0> module A; B; end > => 10 > irb(main):003:0> A::B > NameError: uninitialized constant A::B > from (irb):3 > > However it seems impossible to detect which case we are in within the > const_missing method. A more detailed explanation follows: What about autoload? $ echo 'B = 10' > b.rb $ irb irb(main):001:0> autoload :B, "b" => nil irb(main):002:0> module A;end => nil irb(main):003:0> A::B NameError: uninitialized constant A::B from (irb):3 from :0 irb(main):004:0> module A;B;end => 10 irb(main):005:0> A::B NameError: uninitialized constant A::B from (irb):5 from :0 irb(main):006:0> -- Nobu Nakada