diff options
author | José Valim <jose.valim@gmail.com> | 2012-04-28 00:15:44 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-04-28 00:15:44 -0700 |
commit | d0e1c692b455093ca958a70e2d729b8b17b3f02b (patch) | |
tree | eea4a6b99c3161b4809167a505b185c18481901e | |
parent | dd5524a70741e75d6232d0933f57793a33de5482 (diff) | |
parent | 9d1f6edbe0aa6f95f55464136e39fb4e2e4643f2 (diff) | |
download | rails-d0e1c692b455093ca958a70e2d729b8b17b3f02b.tar.gz rails-d0e1c692b455093ca958a70e2d729b8b17b3f02b.tar.bz2 rails-d0e1c692b455093ca958a70e2d729b8b17b3f02b.zip |
Merge pull request #6024 from carlosantoniodasilva/amo-dirty-refactor
Improve AMo::Dirty *_will_change! method
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d327913824..7f7fb90d87 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -151,13 +151,15 @@ module ActiveModel # Handle <tt>*_will_change!</tt> for +method_missing+. def attribute_will_change!(attr) + return if attribute_changed?(attr) + begin value = __send__(attr) value = value.duplicable? ? value.clone : value rescue TypeError, NoMethodError end - changed_attributes[attr] = value unless changed_attributes.include?(attr) + changed_attributes[attr] = value end # Handle <tt>reset_*!</tt> for +method_missing+. |