instance method
diff
Ruby on Rails 3.1.12
Since v3.0.20 Last seen in v4.0.13Signature
diff(h2)
Returns a hash that represents the difference between two hashes.
Examples:
{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
-
h2req
Source
# File activesupport/lib/active_support/core_ext/hash/diff.rb, line 10
def diff(h2)
dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
end
Defined in activesupport/lib/active_support/core_ext/hash/diff.rb line 10
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash