aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-26 13:44:53 +0930
committerMatthew Draper <matthew@trebex.net>2017-09-01 14:27:13 +0930
commit50dbf817d43569c54300827b5f88702eba12dad6 (patch)
treedc9ed4628ea1e6f5d0f0591d76ac7024ca147814 /activesupport
parent2e6658ae510e17e9e6e98ebd784066752ea6027c (diff)
downloadrails-50dbf817d43569c54300827b5f88702eba12dad6.tar.gz
rails-50dbf817d43569c54300827b5f88702eba12dad6.tar.bz2
rails-50dbf817d43569c54300827b5f88702eba12dad6.zip
Self-alias doesn't suppress the warning on Ruby 2.2
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/module/redefine_method.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/redefine_method.rb b/activesupport/lib/active_support/core_ext/module/redefine_method.rb
index 5bd8e6e973..a0a6622ca4 100644
--- a/activesupport/lib/active_support/core_ext/module/redefine_method.rb
+++ b/activesupport/lib/active_support/core_ext/module/redefine_method.rb
@@ -1,14 +1,23 @@
# frozen_string_literal: true
class Module
- # Marks the named method as intended to be redefined, if it exists.
- # Suppresses the Ruby method redefinition warning. Prefer
- # #redefine_method where possible.
- def silence_redefinition_of_method(method)
- if method_defined?(method) || private_method_defined?(method)
- # This suppresses the "method redefined" warning; the self-alias
- # looks odd, but means we don't need to generate a unique name
- alias_method method, method
+ if RUBY_VERSION >= "2.3"
+ # Marks the named method as intended to be redefined, if it exists.
+ # Suppresses the Ruby method redefinition warning. Prefer
+ # #redefine_method where possible.
+ def silence_redefinition_of_method(method)
+ if method_defined?(method) || private_method_defined?(method)
+ # This suppresses the "method redefined" warning; the self-alias
+ # looks odd, but means we don't need to generate a unique name
+ alias_method method, method
+ end
+ end
+ else
+ def silence_redefinition_of_method(method)
+ if method_defined?(method) || private_method_defined?(method)
+ alias_method :__rails_redefine, method
+ remove_method :__rails_redefine
+ end
end
end