Class: T::HashType
- Inherits:
-
Object
- Object
- T::HashType
- Defined in:
- lib/emery/type.rb
Instance Attribute Summary collapse
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #check(value) ⇒ Object
-
#initialize(key_type, value_type) ⇒ HashType
constructor
A new instance of HashType.
- #to_s ⇒ Object
Constructor Details
#initialize(key_type, value_type) ⇒ HashType
Returns a new instance of HashType.
79 80 81 82 |
# File 'lib/emery/type.rb', line 79 def initialize(key_type, value_type) @key_type = key_type @value_type = value_type end |
Instance Attribute Details
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
77 78 79 |
# File 'lib/emery/type.rb', line 77 def key_type @key_type end |
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
78 79 80 |
# File 'lib/emery/type.rb', line 78 def value_type @value_type end |
Instance Method Details
#==(other) ⇒ Object
96 97 98 |
# File 'lib/emery/type.rb', line 96 def ==(other) T.instance_of?(HashType, other) and self.key_type == other.key_type and self.value_type == other.value_type end |
#check(value) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/emery/type.rb', line 86 def check(value) T.check_not_nil(self, value) if !value.is_a? Hash raise TypeError.new("Value '#{value.inspect.to_s}' type is #{value.class} - Hash is required") end value.each do |item_key, item_value| T.check(@key_type, item_key) T.check(@value_type, item_value) end end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/emery/type.rb', line 83 def to_s "Hash[#{@key_type.to_s}, #{@value_type.to_s}]" end |