Skip to content
Browse files

Merge pull request #2371 from bradediger/issue-2346

remove_possible_method: test if method exists
  • Loading branch information...
2 parents 779d78d + 7f88539 commit e022c95eeea0b99f3919223ea446b261bf3c5f43 @jonleighton jonleighton committed Jul 31, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 activesupport/lib/active_support/core_ext/module/remove_method.rb
View
9 activesupport/lib/active_support/core_ext/module/remove_method.rb
@@ -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 e022c95

Please sign in to comment.
Something went wrong with that request. Please try again.