1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #24511 from lihanli/activemodel-dirty-attribute-changed

speed up ActiveModel::Dirty#attribute_changed?
This commit is contained in:
Jeremy Daer 2016-04-11 15:14:44 -07:00
commit 20ffb63c2e

View file

@ -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