Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / hash / diff.rb
1 module ActiveSupport #:nodoc:
2 module CoreExtensions #:nodoc:
3 module Hash #:nodoc:
4 module Diff
5 # Returns a hash that represents the difference between two hashes.
6 #
7 # Examples:
8 #
9 # {1 => 2}.diff(1 => 2) # => {}
10 # {1 => 2}.diff(1 => 3) # => {1 => 2}
11 # {}.diff(1 => 2) # => {1 => 2}
12 # {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
13 def diff(h2)
14 self.dup.delete_if { |k, v| h2[k] == v }.merge(h2.dup.delete_if { |k, v| self.has_key?(k) })
15 end
16 end
17 end
18 end
19 end