class DuckTesting::Type::Hash
Attributes
key_types[R]
value_types[R]
Public Class Methods
new(key_types, value_types)
click to toggle source
@param key_types
[Array<DuckTesting::Type::Base>] @param value_types
[Array<DuckTesting::Type::Base>]
# File lib/duck_testing/type/hash.rb, line 10 def initialize(key_types, value_types) @key_types = key_types @value_types = value_types end
Public Instance Methods
match?(object)
click to toggle source
@param object [Object] @return [Boolean]
# 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_s()
click to toggle source
@return [String]
# File lib/duck_testing/type/hash.rb, line 23 def to_s "Hash{#{key_types_to_s} => #{value_types_to_s}}" end
Private Instance Methods
key_types_to_s()
click to toggle source
@return [String]
# File lib/duck_testing/type/hash.rb, line 50 def key_types_to_s key_types.map(&:to_s).join(", ") end
match_keys?(hash)
click to toggle source
@param hash [Hash] @return [Boolean]
# File lib/duck_testing/type/hash.rb, line 31 def match_keys?(hash) hash.keys.all? do |key| key_types.all? do |type| type.match?(key) end end end
match_values?(hash)
click to toggle source
@param hash [Hash] @return [Boolean]
# File lib/duck_testing/type/hash.rb, line 41 def match_values?(hash) hash.values.all? do |key| value_types.all? do |type| type.match?(key) end end end
value_types_to_s()
click to toggle source
@return [String]
# File lib/duck_testing/type/hash.rb, line 55 def value_types_to_s value_types.map(&:to_s).join(", ") end