From: Brian Candler Date: 2009-08-06T21:32:10+09:00 Subject: Re: Kernel's module methods? James Coglan wrote: > I think the point being raised is that when you mix a module into a > class, > the class gains the module's instance methods, but not its > module/singleton > methods. So it seems that the only way you'd be able to call Kernel's > module > methods without a receiver would be if `self` were equal to `Kernel`. Yes, but are you sure they are module methods, not just instance methods? > But > seeing as how you can call these methods sans receiver anywhere in your > program, I assume the Kernel methods are given special treatment and > don't > follow the usual scoping rules for method calls. Everywhere in your program, you are inside some instance of Object (or a subclass of Object). And therefore self is that object, and that object inherits Kernel's instance methods. e.g. class Foo def bar puts "hello" end end foo = Foo.new foo.bar The 'puts' inside method :bar is calling foo.puts. Since you haven't defined your own instance method 'puts' in the Foo class, then it follows the class hierarchy back up to Kernel. No special casing involved. That is: AFAICS, this would make sense as long as foo were an instance method of module Kernel, not a module/singleton method. Also note: foo.puts #=> private method `puts' called for # So it seems 'puts' is an instance method of our class, albeit a private one. Or have I got this completely wrong? -- Posted via http://www.ruby-forum.com/.