aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2016-04-11 15:14:44 -0700
committerJeremy Daer <jeremydaer@gmail.com>2016-04-11 15:14:44 -0700
commit20ffb63c2eb8ca65dc0d946deeadb8b4dda7ff3c (patch)
tree55131bf8836a86531cfefce22dfb0063b6f70518 /activemodel
parent94697bb8e74c91fe14581cf6c245f4d4d0d3c710 (diff)
parent73e2dbe651566dbda20002c6184e334c471e1195 (diff)
downloadrails-20ffb63c2eb8ca65dc0d946deeadb8b4dda7ff3c.tar.gz
rails-20ffb63c2eb8ca65dc0d946deeadb8b4dda7ff3c.tar.bz2
rails-20ffb63c2eb8ca65dc0d946deeadb8b4dda7ff3c.zip
Merge pull request #24511 from lihanli/activemodel-dirty-attribute-changed
speed up ActiveModel::Dirty#attribute_changed?
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/dirty.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index 6e2e5afd1b..fad4de9df5 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -174,10 +174,12 @@ module ActiveModel
end
# Handles <tt>*_changed?</tt> for +method_missing+.
- def attribute_changed?(attr, options = {}) #:nodoc:
+ def attribute_changed?(attr, options = nil) #:nodoc:
result = changes_include?(attr)
- result &&= options[:to] == __send__(attr) if options.key?(:to)
- result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
+ if options
+ result &&= options[:to] == __send__(attr) if options.key?(:to)
+ result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
+ end
result
end