Skip to content

Commit

Permalink
remove_possible_method: test if method exists
Browse files Browse the repository at this point in the history
This speeds up remove_possible_method substantially since it doesn't
have to rescue a NameError in the common case.

Closes #2346.
  • Loading branch information
bradediger committed Jul 31, 2011
1 parent 4c85c4e commit 7f88539
Showing 1 changed file with 7 additions and 2 deletions.
@@ -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

0 comments on commit 7f88539

Please sign in to comment.