Sha256: ece09434595aaa194dc6f7ee151c3d0ec2a7c5e0aaaf246deb386f02b27a34a8

Contents?: true

Size: 410 Bytes

Versions: 325

Compression:

Stored size: 410 Bytes

Contents

class Hash
  # 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}
  def diff(h2)
    dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
  end
end

Version data entries

325 entries across 281 versions & 29 rubygems

Version Path
activesupport-3.0.0.beta3 lib/active_support/core_ext/hash/diff.rb
activesupport-3.0.0.beta2 lib/active_support/core_ext/hash/diff.rb
activesupport-3.0.0.beta lib/active_support/core_ext/hash/diff.rb
activesupport-3.0.pre lib/active_support/core_ext/hash/diff.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/hash/diff.rb