Class: Literal::Types::HashType Private
- Inherits:
-
Object
- Object
- Literal::Types::HashType
- Includes:
- Literal::Type
- Defined in:
- lib/literal/types/hash_type.rb
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.
Instance Attribute Summary collapse
- #key_type ⇒ Object readonly private
- #value_type ⇒ Object readonly private
Instance Method Summary collapse
- #===(value) ⇒ Object private
- #>=(other) ⇒ Object private
-
#initialize(key_type, value_type) ⇒ HashType
constructor
private
A new instance of HashType.
- #inspect ⇒ Object private
- #record_literal_type_errors(context) ⇒ Object private
Constructor Details
#initialize(key_type, value_type) ⇒ HashType
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 a new instance of HashType.
7 8 9 10 11 |
# File 'lib/literal/types/hash_type.rb', line 7 def initialize(key_type, value_type) @key_type = key_type @value_type = value_type freeze end |
Instance Attribute Details
#key_type ⇒ Object (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.
13 14 15 |
# File 'lib/literal/types/hash_type.rb', line 13 def key_type @key_type end |
#value_type ⇒ Object (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.
13 14 15 |
# File 'lib/literal/types/hash_type.rb', line 13 def value_type @value_type end |
Instance Method Details
#===(value) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/literal/types/hash_type.rb', line 19 def ===(value) return false unless Hash === value value.each do |k, v| return false unless @key_type === k && @value_type === v end true end |
#>=(other) ⇒ Object
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.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/literal/types/hash_type.rb', line 29 def >=(other) case other when Literal::Types::HashType ( Literal.subtype?(other.key_type, @key_type) ) && ( Literal.subtype?(other.value_type, @value_type) ) else false end end |
#inspect ⇒ Object
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.
15 16 17 |
# File 'lib/literal/types/hash_type.rb', line 15 def inspect "_Hash(#{@key_type.inspect}, #{@value_type.inspect})" end |
#record_literal_type_errors(context) ⇒ Object
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/literal/types/hash_type.rb', line 42 def record_literal_type_errors(context) unless Hash === context.actual return end context.actual.each do |key, item| unless @key_type === key context.add_child(label: "[]", expected: @key_type, actual: key) next end unless @value_type === item context.add_child(label: "[#{key.inspect}]", expected: @value_type, actual: item) end end end |