[ruby-core:77981] [Ruby trunk Feature#12268][Rejected] Open3 should use extend self instead of module_function calls
From:
akr@...
Date:
2016-11-05 14:33:04 UTC
List:
ruby-core #77981
Issue #12268 has been updated by Akira Tanaka.
Status changed from Open to Rejected
module_function is the standard way to define module methods.
I think it is because "include mod" makes us possible to call module methods without module name,
as "popen3(...)" instead of "Open3.popen3(...)",
"sin(...)" instead of "Math.sin(...)", etc.,
without providing the methods as public API.
"extend self" style makes applications which uses "include mod" will provide the methods as public API
which is not intentional in most cases.
(Most applications should not provide popen3() or sin() method as public API.)
If you really want it, you can invoke "public" method.
```
% ruby -e '
module M
def m
:m
end
module_function :m
end
class C
include M
end
p C.new.m
'
-e:11:in `<main>': private method `m' called for #<C:0x007f8b5fbd3d68> (NoMethodError)
% ruby -e '
module M
def m
:m
end
extend self
end
class C
include M
end
p C.new.m
'
:m
% ruby -e '
module M
def m
:m
end
module_function :m
end
class C
include M
public :m
end
p C.new.m
'
:m
```
----------------------------------------
Feature #12268: Open3 should use extend self instead of module_function calls
https://bugs.ruby-lang.org/issues/12268#change-61315
* Author: Dan Rathbun
* Status: Rejected
* Priority: Normal
* Assignee:
----------------------------------------
Open3 should use `extend self` instead of `module_function` calls after defining each method.
Using `module_function` causes access issues when the `Open3` module is mixed into other class or module namespaces. Ie, the very method proxies I wish to use in my "mixee" class, get created as private because of `module_function` in "open3.rb".
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>