From: Ruby-Lang@... Date: 2016-09-04T16:27:58+00:00 Subject: [ruby-core:77145] [Ruby trunk Feature#12721] public_module_function Issue #12721 has been updated by J��rg W Mittag. If `module_function` returned its argument(s), we could write ~~~ruby module Foo public module_function def hi puts 'hi from method hi() in module Foo' end end ~~~ But I'm not sure that's worth it. The *whole point* of "functions" is that they *don't* have receiver! Why would you want to call them with one? ---------------------------------------- Feature #12721: public_module_function https://bugs.ruby-lang.org/issues/12721#change-60360 * Author: Robert A. Heiler * Status: Open * Priority: Normal * Assignee: ---------------------------------------- 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: ```ruby 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 ```ruby public_module_function ``` If I would have a public variant, I assume that I could get rid of "`def self.foo`" statements in some of my modules. -- https://bugs.ruby-lang.org/ Unsubscribe: