Sha256: 3e3722cdf25774e3694d51820e3207444dc91b71d3a9235a6161b12b05e6d7d5

Contents?: true

Size: 753 Bytes

Versions: 3

Compression:

Stored size: 753 Bytes

Contents

if defined? ActiveSupport
  class Hash
    # Will return a new hash that does not differentiate
    # between string and symbol keys for equality.
    #
    # ```ruby
    # {a: 1} == {"a" => 1}.with_indifferent_equality #=> true
    # ```
    def with_indifferent_equality
      TFG::Support::HashWithIndifferentEquality.new(self)
    end

    # Aliased to original {Hash#==}.
    alias_method :old_double_equals, :==

    # Check equality of hashes, considering if difference
    # between string and symbol keys should be observed.
    # See {Hash#with_indifferent_equality}.
    def ==(other)
      if other.is_a?(TFG::Support::HashWithIndifferentEquality)
        other == self
      else
        old_double_equals(other)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tfg_support-1.1.1 lib/tfg/support/core_ext/hash/with_indifferent_equality.rb
tfg_support-1.0.1 lib/tfg/support/core_ext/hash/with_indifferent_equality.rb
tfg_support-1.0.0 lib/tfg/support/core_ext/hash/with_indifferent_equality.rb