diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-26 06:48:04 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-26 06:48:04 -0600 |
commit | 6616cb866eaf68e44dfd3324ffd543c9ce16869c (patch) | |
tree | 4ad237151b10a7efdeea8f7884c7940c306da5a8 /activesupport/lib/active_support | |
parent | 09463183867f702d6ec66fce964ecb9f7ae0d98a (diff) | |
parent | 7189e5554e44928698b01c59e833edfbebf0c6be (diff) | |
download | rails-6616cb866eaf68e44dfd3324ffd543c9ce16869c.tar.gz rails-6616cb866eaf68e44dfd3324ffd543c9ce16869c.tar.bz2 rails-6616cb866eaf68e44dfd3324ffd543c9ce16869c.zip |
Merge pull request #22071 from yui-knk/redefine_method_keep_visibility
Make `Module#redefine_method` to keep method visibility
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/remove_method.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb index 287ec477a0..d5ec16d68a 100644 --- a/activesupport/lib/active_support/core_ext/module/remove_method.rb +++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb @@ -16,7 +16,20 @@ class Module # Replaces the existing method definition, if there is one, with the passed # block as its body. def redefine_method(method, &block) + visibility = method_visibility(method) remove_possible_method(method) define_method(method, &block) + send(visibility, method) + end + + def method_visibility(method) # :nodoc: + case + when private_method_defined?(method) + :private + when protected_method_defined?(method) + :protected + else + :public + end end end |