instance method
diff
Ruby on Rails 4.0.13
Since v3.0.20 Last seen in v4.0.13Signature
diff(other)
Returns a hash that represents the difference between two hashes.
{1 => 2}.diff(1 => 2) # => {}
{1 => 2}.diff(1 => 3) # => {1 => 2}
{}.diff(1 => 2) # => {1 => 2}
{1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
Parameters
-
otherreq
Source
# File activesupport/lib/active_support/core_ext/hash/diff.rb, line 8
def diff(other)
ActiveSupport::Deprecation.warn "Hash#diff is no longer used inside of Rails, and is being deprecated with no replacement. If you're using it to compare hashes for the purpose of testing, please use MiniTest's assert_equal instead."
dup.
delete_if { |k, v| other[k] == v }.
merge!(other.dup.delete_if { |k, v| has_key?(k) })
end
Defined in activesupport/lib/active_support/core_ext/hash/diff.rb line 8
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash