aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/remove_method.rb
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2015-10-26 18:12:51 +0900
committeryui-knk <spiketeika@gmail.com>2015-10-26 19:40:46 +0900
commit7189e5554e44928698b01c59e833edfbebf0c6be (patch)
tree4ad237151b10a7efdeea8f7884c7940c306da5a8 /activesupport/lib/active_support/core_ext/module/remove_method.rb
parent09463183867f702d6ec66fce964ecb9f7ae0d98a (diff)
downloadrails-7189e5554e44928698b01c59e833edfbebf0c6be.tar.gz
rails-7189e5554e44928698b01c59e833edfbebf0c6be.tar.bz2
rails-7189e5554e44928698b01c59e833edfbebf0c6be.zip
Make `Module#redefine_method` to keep method visibility
Before this commit `Module#redefine_method` always changes visibility of redefined method to `public`. This commit changes behavior of Module#redefine_method` to keep method visibility.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/remove_method.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/remove_method.rb13
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