提交 50dbf817 编写于 作者: M Matthew Draper

Self-alias doesn't suppress the warning on Ruby 2.2

上级 2e6658ae
# frozen_string_literal: true # frozen_string_literal: true
class Module class Module
# Marks the named method as intended to be redefined, if it exists. if RUBY_VERSION >= "2.3"
# Suppresses the Ruby method redefinition warning. Prefer # Marks the named method as intended to be redefined, if it exists.
# #redefine_method where possible. # Suppresses the Ruby method redefinition warning. Prefer
def silence_redefinition_of_method(method) # #redefine_method where possible.
if method_defined?(method) || private_method_defined?(method) def silence_redefinition_of_method(method)
# This suppresses the "method redefined" warning; the self-alias if method_defined?(method) || private_method_defined?(method)
# looks odd, but means we don't need to generate a unique name # This suppresses the "method redefined" warning; the self-alias
alias_method method, method # 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
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册