Feature #12721
closedpublic_module_function
Description
Hello ruby core,
This is about module_function(). As the documentation rightfully
states, it adds a private method when included ("mixed in") into
a class.
The following code shows that this works:
module Foo
module_function
def hi
puts 'hi from method hi() in module Foo'
end
end
class Bar
include Foo
def test
hi
end
end
Bar.new.test # This works
Bar.new.hi # This here leads to an error message "private method `hi' called"
I am sure that the private method by default makes sense, but
I wondered in those case where I would like the above to be
a public variant.
Is there some functionality like module_function but that
works as a public method instead? So that the last example,
Bar.new.hi, would also work?
Something like
If I would have a public variant, I assume that I could get rid of
"def self.foo" statements in some of my modules.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Description updated (diff)
Updated by jwmittag (Jörg W Mittag) almost 10 years ago
Updated by matz (Yukihiro Matsumoto) over 9 years ago
- Status changed from Open to Rejected
I understand your proposal, but I don't see what it is for.
Do you have any no-artificial use-case for this feature?
If you come up with real-world use-case, please re-open the issue.
Matz.