Class: NRSER::Types::HashOfType
- Defined in:
- lib/nrser/types/hashes.rb
Overview
A Hash type with typed keys and/or values.
Instance Attribute Summary collapse
-
#keys ⇒ NRSER::Types::Type
readonly
The type of the hash keys.
-
#values ⇒ NRSER::Types::Type
readonly
The type of the hash values.
Attributes inherited from IsA
Instance Method Summary collapse
- #explain ⇒ String
- #has_from_s? ⇒ Boolean
-
#initialize(keys: NRSER::Types.any, values: NRSER::Types.any, **options) ⇒ HashOfType
constructor
Constructor ========================================================================.
- #test?(value) ⇒ Boolean
Methods inherited from IsA
#==, #custom_from_data, #has_from_data?, #init_from_data?
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
#initialize(keys: NRSER::Types.any, values: NRSER::Types.any, **options) ⇒ HashOfType
Constructor
136 137 138 139 140 141 142 143 |
# File 'lib/nrser/types/hashes.rb', line 136 def initialize keys: NRSER::Types.any, values: NRSER::Types.any, ** super ** @keys = NRSER::Types.make keys @values = NRSER::Types.make values end |
Instance Attribute Details
#keys ⇒ NRSER::Types::Type (readonly)
The type of the hash keys.
123 124 125 |
# File 'lib/nrser/types/hashes.rb', line 123 def keys @keys end |
#values ⇒ NRSER::Types::Type (readonly)
The type of the hash values.
130 131 132 |
# File 'lib/nrser/types/hashes.rb', line 130 def values @values end |
Instance Method Details
#explain ⇒ String
176 177 178 |
# File 'lib/nrser/types/hashes.rb', line 176 def explain "Hash<#{ keys.explain }, #{ values.explain }>" end |
#has_from_s? ⇒ Boolean
154 155 156 |
# File 'lib/nrser/types/hashes.rb', line 154 def has_from_s? !@from_s.nil? || [keys, values].all?( &:has_from_s ) end |
#test?(value) ⇒ Boolean
163 164 165 166 167 168 169 |
# File 'lib/nrser/types/hashes.rb', line 163 def test? value return false unless super( value ) value.all? { |k, v| keys.test( k ) && values.test( v ) } end |