Class: ValueSemantics::HashOf

Inherits:
Object
  • Object
show all
Defined in:
lib/value_semantics/hash_of.rb

Overview

Validator that matches Hashes with homogeneous keys and values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_validator, value_validator) ⇒ HashOf

Returns a new instance of HashOf.



8
9
10
11
# File 'lib/value_semantics/hash_of.rb', line 8

def initialize(key_validator, value_validator)
  @key_validator, @value_validator = key_validator, value_validator
  freeze
end

Instance Attribute Details

#key_validatorObject (readonly)

Returns the value of attribute key_validator.



6
7
8
# File 'lib/value_semantics/hash_of.rb', line 6

def key_validator
  @key_validator
end

#value_validatorObject (readonly)

Returns the value of attribute value_validator.



6
7
8
# File 'lib/value_semantics/hash_of.rb', line 6

def value_validator
  @value_validator
end

Instance Method Details

#===(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/value_semantics/hash_of.rb', line 14

def ===(value)
  Hash === value && value.all? do |key, value|
    key_validator === key && value_validator === value
  end
end