diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-07-31 07:28:50 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-07-31 07:28:50 -0700 |
commit | e022c95eeea0b99f3919223ea446b261bf3c5f43 (patch) | |
tree | f4bd65a3658c9a1cd52ee55ae6ff9410006377f6 | |
parent | 779d78d5913b910cd83a081effd5adc508e8500b (diff) | |
parent | 7f885390876a3acdfa962e42b2bf2c73241e8702 (diff) | |
download | rails-e022c95eeea0b99f3919223ea446b261bf3c5f43.tar.gz rails-e022c95eeea0b99f3919223ea446b261bf3c5f43.tar.bz2 rails-e022c95eeea0b99f3919223ea446b261bf3c5f43.zip |
Merge pull request #2371 from bradediger/issue-2346
remove_possible_method: test if method exists
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/remove_method.rb | 9 |
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 |