Sha256: e26ab58137d7804eb608de8d7bb00392cdadb7f7708a50dc1eaf591df73fa93a

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

##
# @example
#   {foo: (1..10), bar: /abc/} == {foo: 5, bar: :abc}
#   # => false, since values are compared by `#==` under the hood.
#
#   ConvenientService::Utils::Hash::TripleEqualityCompare.call({foo: (1..10), bar: /abc/}, {foo: 5, bar: :abc})
#   # => true, since values are compared by `#===` under the hood.
#
module ConvenientService
  module Utils
    module Hash
      class TripleEqualityCompare < Support::Command
        ##
        # @!attribute [r] hash
        #   @return [Hash]
        #
        attr_reader :hash

        ##
        # @!attribute [r] other_hash
        #   @return [Array]
        #
        attr_reader :other_hash

        ##
        # @param hash [Hash]
        # @param other_hash [Hash]
        # @return [void]
        #
        def initialize(hash, other_hash)
          @hash = hash
          @other_hash = other_hash
        end

        ##
        # @return [Boolean]
        #
        def call
          return false if hash.size != other_hash.size
          return false if hash.keys.difference(other_hash.keys).any?

          return false unless hash.all? { |key, value| value === other_hash[key] }

          true
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.19.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.18.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.17.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.16.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.15.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.14.0 lib/convenient_service/utils/hash/triple_equality_compare.rb
convenient_service-0.13.0 lib/convenient_service/utils/hash/triple_equality_compare.rb