Feature #12495
Make "private" return the arguments again, for chaining
Description
Ruby 2.1 introduced the feature to make def foo
return the symbol, so this could be used by things like private
(see #3753):
private def foo() end
You could use the same method to create your own decorators (name borrowed from Python)
def cached(name)
# Rewrite method to include a cache
return name
end
private cached def foo() end
Currently, this would work but cached private def foo()
would not. private
(and all other modifier functions) return the class on which it was called. It would be nice to exterminate those order-dependencies.
The attached patch fixes this. It includes three modes:
No arguments: return nil
:
private
def foo() end
One argument: return the symbol. The would be the most common use case for this example.
private def foo() end
private :bar
Multiple arguments: return an array of the arguments:
private :foo, :bar
Files
Updated by herwinw (Herwin Quarantainenet) over 4 years ago
The patch is written for Ruby 2.3.1, just because the tests were broken in trunk.
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Status changed from Open to Feedback
Only private
, not public
, protected
and module_function
?
Herwin Quarantainenet wrote:
The patch is written for Ruby 2.3.1, just because the tests were broken in trunk.
How broken?
Updated by herwinw (Herwin Quarantainenet) over 4 years ago
Only
private
, notpublic
,protected
andmodule_function
?
private
, public
and protected
all use set_visibility
, that's where the change is implemented, private
was just used as an example. module_function
/rb_mod_modfunc
has not been updated, but that's an easy fix.
How broken?
Something with the openssl tests. Travis showed them red as well, but thinks it's okay by now. The comment was intended to justify any file offsets, further discussion about it would be rather irrelevant to this case.