Class: NRSER::Types::HashOfType
- Defined in:
- lib/nrser/types/hashes.rb
Overview
Note:
Construct HashOfType types using the Hash factory.
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 HashType
Methods inherited from IsA
#==, #custom_from_data, #has_from_data?, #init_from_data?
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #default_name, #default_symbolic, #from_data, #from_s, #has_from_data?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #symbolic, #test, #to_data, #to_proc, #to_s, #union, #xor
Constructor Details
#initialize(keys: NRSER::Types.any, values: NRSER::Types.any, **options) ⇒ HashOfType
Constructor
166 167 168 169 170 171 172 173 |
# File 'lib/nrser/types/hashes.rb', line 166 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.
153 154 155 |
# File 'lib/nrser/types/hashes.rb', line 153 def keys @keys end |
#values ⇒ NRSER::Types::Type (readonly)
The type of the hash values.
160 161 162 |
# File 'lib/nrser/types/hashes.rb', line 160 def values @values end |
Instance Method Details
#explain ⇒ String
206 207 208 |
# File 'lib/nrser/types/hashes.rb', line 206 def explain "Hash<#{ keys.explain }, #{ values.explain }>" end |
#has_from_s? ⇒ Boolean
184 185 186 |
# File 'lib/nrser/types/hashes.rb', line 184 def has_from_s? !@from_s.nil? || [keys, values].all?( &:has_from_s ) end |
#test?(value) ⇒ Boolean
193 194 195 196 197 198 199 |
# File 'lib/nrser/types/hashes.rb', line 193 def test? value return false unless super( value ) value.all? { |k, v| keys.test( k ) && values.test( v ) } end |