Merge pull request #2371 from bradediger/issue-2346

remove_possible_method: test if method exists
This commit is contained in:
Jon Leighton
2011-07-31 07:28:50 -07:00

View File

@@ -1,11 +1,16 @@
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
end