diff options
author | Matthew Draper <matthew@trebex.net> | 2017-05-26 13:12:21 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-09-01 14:27:13 +0930 |
commit | 2e6658ae510e17e9e6e98ebd784066752ea6027c (patch) | |
tree | a5424b329e24f37cab0b6e4698b39a0ac592573f /guides/source | |
parent | 2cd8ac1b68ba04ca12a816c8113271017b3c43c4 (diff) | |
download | rails-2e6658ae510e17e9e6e98ebd784066752ea6027c.tar.gz rails-2e6658ae510e17e9e6e98ebd784066752ea6027c.tar.bz2 rails-2e6658ae510e17e9e6e98ebd784066752ea6027c.zip |
Clarify intentions around method redefinitions
Don't use remove_method or remove_possible_method just before a new
definition: at best the purpose is unclear, and at worst it creates a
race condition.
Instead, prefer redefine_method when practical, and
silence_redefinition_of_method otherwise.
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 9f89e666dc..b43d13b804 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -864,7 +864,11 @@ There are cases where you need to define a method with `define_method`, but don' The method `redefine_method` prevents such a potential warning, removing the existing method before if needed. -NOTE: Defined in `active_support/core_ext/module/remove_method.rb`. +You can also use `silence_redefinition_of_method` if you need to define +the replacement method yourself (because you're using `delegate`, for +example). + +NOTE: Defined in `active_support/core_ext/module/redefine_method.rb`. Extensions to `Class` --------------------- |