From: Trans Date: 2008-10-22T20:08:10+09:00 Subject: Re: Why ?? On Oct 22, 2:50 am, Kyung won Cheon wrote: > ## in irb > > > > >> self > => main > >> def why? > >> end > => nil > >> self.why? > => nil > > ## in test.rb > > p self        # => main > def why? > end > self.why?     # private method 'why?' called for main:Object > (NoMethodError) > > ## Anyway, one more.. > > ## in test2.rb > > def why? > end > > class A > end > > p A.private_method_defined?(:why?) # true > > # How is 'why?' inherited??? > # The 'main' is a instance of Object but it's not a Object? > > # I understand if ... > # class Object > #   private > #   def why? > #   end > # end > > ############## > # Help Me^^ > ############## The toplevel object (aka 'main') delegates some module-equivalent methods to Object class. So when you say def why? end What actually happens is: class Object def why? end private :why? end Not all module methods are delegated, try using define_method(:why?) at the toplevel instead and it will bomb. T. P.S. Personally, I find the whole setup rather half-baked, and have continually advocated for the replacement of the current toplevel object with a self extended module.