Sha256: 3b6b1e0e35f3569b090c3d23d13444e45e1c680c77b0b330a6c465b8579b57f6

Contents?: true

Size: 543 Bytes

Versions: 2

Compression:

Stored size: 543 Bytes

Contents

module HashDiff

  refine Hash do
    # Stolen from Rails 4.0.5 since this has been removed!
    #
    # Returns a hash that represents the diff_witherence between two hashes.
    #
    #   {1 => 2}.diff_with(1 => 2)         # => {}
    #   {1 => 2}.diff_with(1 => 3)         # => {1 => 2}
    #   {}.diff_with(1 => 2)               # => {1 => 2}
    #   {1 => 2, 3 => 4}.diff_with(1 => 2) # => {3 => 4}
    def diff_with other
      dup.delete_if { |k, v| other[k] == v }.merge!(other.dup.delete_if { |k, v| has_key?(k) })
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validation_matcher-3.0.1 lib/validation_matcher/hash_diff.rb
validation_matcher-3.0.0 lib/validation_matcher/hash_diff.rb