Class: DuckTesting::Type::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/duck_testing/type/hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_types, value_types) ⇒ Hash

Returns a new instance of Hash.

Parameters:



10
11
12
13
# File 'lib/duck_testing/type/hash.rb', line 10

def initialize(key_types, value_types)
  @key_types = key_types
  @value_types = value_types
end

Instance Attribute Details

#key_typesObject (readonly)

Returns the value of attribute key_types.



6
7
8
# File 'lib/duck_testing/type/hash.rb', line 6

def key_types
  @key_types
end

#value_typesObject (readonly)

Returns the value of attribute value_types.



6
7
8
# File 'lib/duck_testing/type/hash.rb', line 6

def value_types
  @value_types
end

Instance Method Details

#match?(object) ⇒ Boolean

Parameters:

  • object (Object)

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/duck_testing/type/hash.rb', line 17

def match?(object)
  return false unless object.is_a?(::Hash)
  match_keys?(object) && match_values?(object)
end

#to_sString

Returns:

  • (String)


23
24
25
# File 'lib/duck_testing/type/hash.rb', line 23

def to_s
  "Hash{#{key_types_to_s} => #{value_types_to_s}}"
end