class NRSER::Types::HashType::HashOfType
A {Hash} type with typed keys and/or values.
@note
Construct {HashOfType} types using the {.Hash} factory.
Attributes
keys[R]
The type of the hash keys.
@return [NRSER::Types::Type]
values[R]
The type of the hash values.
@return [NRSER::Types::Type]
Public Class Methods
new(keys: NRSER::Types.any, values: NRSER::Types.any, **options)
click to toggle source
Constructor
¶ ↑
Calls superclass method
NRSER::Types::HashType::new
# File lib/nrser/types/hashes.rb, line 166 def initialize keys: NRSER::Types.any, values: NRSER::Types.any, **options super **options @keys = NRSER::Types.make keys @values = NRSER::Types.make values end
Public Instance Methods
explain()
click to toggle source
@see NRSER::Types::Type#explain
@return [String]
# File lib/nrser/types/hashes.rb, line 206 def explain "Hash<#{ keys.explain }, #{ values.explain }>" end
has_from_s?()
click to toggle source
Overridden to check that both the {#keys} and {#values} types can load from a string.
@see NRSER::Types::Type#has_from_s?
# File lib/nrser/types/hashes.rb, line 184 def has_from_s? !@from_s.nil? || [keys, values].all?( &:has_from_s ) end
test?(value)
click to toggle source
@return [Boolean]
Calls superclass method
# 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