Class: Strict::Validators::HashOf

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

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/strict/validators/hash_of.rb', line 8

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

Instance Attribute Details

#key_validatorObject (readonly)

Returns the value of attribute key_validator.



6
7
8
# File 'lib/strict/validators/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/strict/validators/hash_of.rb', line 6

def value_validator
  @value_validator
end

Instance Method Details

#===(value) ⇒ Object



13
14
15
16
17
# File 'lib/strict/validators/hash_of.rb', line 13

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

#inspectObject Also known as: to_s



19
20
21
# File 'lib/strict/validators/hash_of.rb', line 19

def inspect
  "HashOf(#{key_validator.inspect} => #{value_validator.inspect})"
end