Class: Contraction::HashType

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/type_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_type, value_type) ⇒ HashType

Returns a new instance of HashType.



93
94
95
96
# File 'lib/parser/type_parser.rb', line 93

def initialize(key_type, value_type)
  @key_type = key_type
  @value_type = value_type
end

Instance Attribute Details

#key_typeObject (readonly)

Returns the value of attribute key_type.



92
93
94
# File 'lib/parser/type_parser.rb', line 92

def key_type
  @key_type
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



92
93
94
# File 'lib/parser/type_parser.rb', line 92

def value_type
  @value_type
end

Instance Method Details

#check(thing) ⇒ Object



98
99
100
101
102
# File 'lib/parser/type_parser.rb', line 98

def check(thing)
  thing.is_a?(Hash) &&
    thing.keys.all? { |k| key_type.check(k) } &&
    thing.values.all? { |v| value_type.check(v) }
end