James Hunt wrote:
I believe the primary different shows up when the module is included
in another class.Using your explicit definition as such:
module MyExplicitModule
def MyExplicitModule.greet
puts "hello, explicitly!"
end
endclass MyExplicitClass
include MyExplicitModuledef hello
greet
end
endMyExplicitModule.greet
MyExplicitClass.new.greetThe output of this code when run is
hello
module_function.rb:31:in `hello': undefined local variable or method
`greet' for #<MyExplicitClass:0xb7cc7eac> (NameError)
from module_function.rb:36
Using your last example with module_function, I get the same result:
module MyModule
def greet
puts "hello"
end
module_function :greet
end
class MyClass
include MyModule
end
MyModule.greet
MyClass.new.greet
--output:--
hello
r1test.rb:13: private method `greet' called for #<MyClass:0x25490>
(NoMethodError)
So, I'm not seeing any difference.
···
--
Posted via http://www.ruby-forum.com/\.