Skip to content
This repository
tree: c0c87922ba
Fetching contributors…

Cannot retrieve contributors at this time

file 14 lines (14 sloc) 0.652 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Hash
  # 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}
  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
end
Something went wrong with that request. Please try again.