Skip to content

Commit

Permalink
Merge pull request #14695 from akshay-vishnoi/doc_changes
Browse files Browse the repository at this point in the history
[ci skip] Remove false documentation
  • Loading branch information
rafaelfranca committed Apr 10, 2014
2 parents 1938c96 + 8c1406c commit 167e6da
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions guides/source/active_support_core_extensions.md
Expand Up @@ -964,20 +964,7 @@ NOTE: Defined in `active_support/core_ext/module/delegation.rb`


There are cases where you need to define a method with `define_method`, but don't know whether a method with that name already exists. If it does, a warning is issued if they are enabled. No big deal, but not clean either. There are cases where you need to define a method with `define_method`, but don't know whether a method with that name already exists. If it does, a warning is issued if they are enabled. No big deal, but not clean either.


The method `redefine_method` prevents such a potential warning, removing the existing method before if needed. Rails uses it in a few places, for instance when it generates an association's API: The method `redefine_method` prevents such a potential warning, removing the existing method before if needed.

```ruby
redefine_method("#{reflection.name}=") do |new_value|
association = association_instance_get(reflection.name)

if association.nil? || association.target != new_value
association = association_proxy_class.new(self, reflection)
end

association.replace(new_value)
association_instance_set(reflection.name, new_value.nil? ? nil : association)
end
```


NOTE: Defined in `active_support/core_ext/module/remove_method.rb` NOTE: Defined in `active_support/core_ext/module/remove_method.rb`


Expand Down

0 comments on commit 167e6da

Please sign in to comment.