From: James Gray Date: 2009-08-06T21:46:38+09:00 Subject: Re: Kernel's module methods? On Aug 6, 2009, at 7:32 AM, Brian Candler wrote: > 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? They are "module functions" actually, implemented with this: ------------------------------------------------- Module#module_function module_function(symbol, ...) => self ------------------------------------------------------------------------ Creates module functions for the named methods. These functions may be called with the module as a receiver, and also become available as instance methods to classes that mix in the module. Module functions are copies of the original, and so may be changed independently. The instance-method versions are made private. If used with no arguments, subsequently defined methods become module functions. module Mod def one "This is one" end module_function :one end class Cls include Mod def callOne one end end Mod.one #=> "This is one" c = Cls.new c.callOne #=> "This is one" module Mod def one "This is the new one" end end Mod.one #=> "This is one" c.callOne #=> "This is the new one" James Edward Gray II