Class: Typeguard::Validation::GenericHash
- Defined in:
- lib/typeguard/types.rb
Instance Method Summary collapse
-
#initialize(node) ⇒ GenericHash
constructor
A new instance of GenericHash.
- #valid?(value) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(node) ⇒ GenericHash
82 83 84 85 86 |
# File 'lib/typeguard/types.rb', line 82 def initialize(node) @klass = node.[:const] @keys = node.children.first.map { |k| Base.from(k) } @values = node.children.last.map { |v| Base.from(v) } end |
Instance Method Details
#valid?(value) ⇒ Boolean
88 89 90 91 92 93 94 95 96 |
# File 'lib/typeguard/types.rb', line 88 def valid?(value) return false unless value.is_a?(@klass) value.all? do |k, v| key_valid = @keys.any? { |child| child.valid?(k) } value_valid = @values.any? { |child| child.valid?(v) } key_valid && value_valid end end |