Module_function semantics

Hi all!

I’m trying to understand some code in the stdlib (drb/drb.rb, to be
particular).

Is there any difference between:

module Foo

module_function
def bar()
  "baz"
end

end

and

module Foo

def Foo.bar()
  "baz"
end

end

?

Am I right in guessing that the former gives both a module and a mixin
function of the same name, whereas the latter gives on a module function?
Or are they in fact identical?

William

  module Foo

    module_function

module_function make a private method and a public singleton method.

    def bar()
      "baz"
    end

  end

For example

svg% cat b.rb
#!/usr/bin/ruby
module A
   def a
      puts "a"
   end
   module_function :a

   def self.b
      puts "b"
   end
end

A.a
A.b

include A
a
b
svg%

svg% b.rb
a
b
a
./b.rb:18: undefined local variable or method `b' for main:Object (NameError)
svg%

Guy Decoux