Note: This question has been posted already at Ruby-Forum without getting an answer
Consider this module:
module MM
def f
end
def self.g
end
module_function :f
end
Both, f
and g
, are module functions, and can be called as
MM::f
MM::g
Is it just a matter of taste, or might there be good reasons to choose one way of defining a module function over the other?
I am aware, that there is a difference, when I am using the module as a mixin:
class CC
include MM
end
In this case, f
is available also as an instance method within CC
, while
g
is not. However, this doesn't look to me as a particularily
interesting feature: If I design a module to be used as a mixin to a
class, I don't see why I would use module_function. Are there other
reasons why I would favorize either self.FUNCTION
or module_function
when defining a module function?