Class: ConvenientService::Utils::Hash::TripleEqualityCompare Private

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/hash/triple_equality_compare.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Examples:

Common usage.

{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.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(hash, other_hash) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Since:

  • 1.0.0



37
38
39
40
# File 'lib/convenient_service/utils/hash/triple_equality_compare.rb', line 37

def initialize(hash, other_hash)
  @hash = hash
  @other_hash = other_hash
end

Instance Attribute Details

#hashObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



24
25
26
# File 'lib/convenient_service/utils/hash/triple_equality_compare.rb', line 24

def hash
  @hash
end

#other_hashObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



30
31
32
# File 'lib/convenient_service/utils/hash/triple_equality_compare.rb', line 30

def other_hash
  @other_hash
end

Instance Method Details

#callBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 1.0.0



45
46
47
48
49
50
# File 'lib/convenient_service/utils/hash/triple_equality_compare.rb', line 45

def call
  return false if hash.size != other_hash.size
  return false if hash.keys.difference(other_hash.keys).any?

  hash.all? { |key, value| value === other_hash[key] }
end