提交 e1b54646 编写于 作者: B Brad Ediger 提交者: Xavier Noria

remove_possible_method: test if method exists

This speeds up remove_possible_method substantially since it doesn't
have to rescue a NameError in the common case.

Closes #2346.
上级 3d2bda96
class Module
def remove_possible_method(method)
remove_method(method)
if method_defined?(method) || private_method_defined?(method)
remove_method(method)
end
rescue NameError
# If the requested method is defined on a superclass or included module,
# method_defined? returns true but remove_method throws a NameError.
# Ignore this.
end
def redefine_method(method, &block)
remove_possible_method(method)
define_method(method, &block)
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册