From: ts Date: 2006-07-05T23:56:04+09:00 Subject: Re: module methods acting like instance methods in extension module >>>>> "J" == John Gabriele writes: J> So, rb_define_module_function does *both*? Ah. Interesting. rb_define_module_function() do the same thing than Module#module_function moulon% ri module_function ------------------------------------------------- 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" moulon% J> Your comment "# will give an error because it's a private method" J> doesn't make sense to me, since just calling 'foo123' does in fact J> work, and foo123 is private. Well, in ruby a private method is a method that you can only call "like a function" (see the thread send/funcall "About 1.9 #__method__ feature"), i.e. without a receiver. In this case foo123 # will work, the method is called without a receiver self.foo123 # will give an error because ruby will try to call # TheModule#foo123 which is private TheModule.foo123 # will work because ruby will call the # singleton method TheModule::foo123, which is # public Guy Decoux