aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorBrad Ediger <brad.ediger@madriska.com>2011-07-31 07:38:38 -0500
committerXavier Noria <fxn@hashref.com>2011-08-13 16:22:25 -0700
commite1b546464ecf20466fb38a93eea9769945774eee (patch)
tree96810552d21f29446b460b779a56d20df86e9998 /activesupport/lib/active_support/core_ext
parent3d2bda9601d3a45f62ad5b7930e453bd1eb01583 (diff)
downloadrails-e1b546464ecf20466fb38a93eea9769945774eee.tar.gz
rails-e1b546464ecf20466fb38a93eea9769945774eee.tar.bz2
rails-e1b546464ecf20466fb38a93eea9769945774eee.zip
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.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/module/remove_method.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb
index 07d7c9b018..b76bc16ee1 100644
--- a/activesupport/lib/active_support/core_ext/module/remove_method.rb
+++ b/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 \ No newline at end of file
+end