Class: ValueSemantics::HashOf
- Inherits:
-
Object
- Object
- ValueSemantics::HashOf
- Defined in:
- lib/value_semantics/hash_of.rb
Overview
Validator that matches Hashes with homogeneous keys and values
Instance Attribute Summary collapse
-
#key_validator ⇒ Object
readonly
Returns the value of attribute key_validator.
-
#value_validator ⇒ Object
readonly
Returns the value of attribute value_validator.
Instance Method Summary collapse
- #===(value) ⇒ Boolean
-
#initialize(key_validator, value_validator) ⇒ HashOf
constructor
A new instance of HashOf.
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_validator ⇒ Object (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_validator ⇒ Object (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
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 |