From: Austin Ziegler Date: 2002-11-13T23:51:29+09:00 Subject: Re: How do module functions work? On Wed, 13 Nov 2002 18:41:50 +0900, Gavin Sinclair wrote: > From: "Yukihiro Matsumoto" >>| Why do you have to use Module#module_function in order to be >>| able to call >>| Foo::bar() >>| And why does it create a copy of the method? I don't understand >>| the mechanics at play here. >> Instance methods and class methods (or module method) are totally >> different entities, so that you have to copy instance methods to >> make them callable as class methods. > So how does it get copied? Can it be expressed in Ruby (like > attr_accessor), or is it more magical that that. module Foo def bar "Foo::bar" end end The only way you can get at this Foo#bar is to include it (which strips the module as a namespace). The two definitions below are functionally equivalent: module Foo def bar "Foo::bar" end def Foo.bar "Foo::bar" end end module Foo def bar "Foo::bar" end module_function :bar end -austin -- Austin Ziegler, austin@halostatue.ca on 2002.11.13 at 09.47.56