Class: Typeguard::Validation::Generic

Inherits:
Base
  • Object
show all
Defined in:
lib/typeguard/types.rb

Instance Method Summary collapse

Methods inherited from Base

from

Constructor Details

#initialize(node) ⇒ Generic

Returns a new instance of Generic.



51
52
53
54
# File 'lib/typeguard/types.rb', line 51

def initialize(node)
  @klass = node.[:const]
  @children = node.children.map { |child| Base.from(child) }
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/typeguard/types.rb', line 56

def valid?(value)
  return false unless value.is_a?(@klass)

  value.all? do |element|
    @children.any? { |child| child.valid?(element) }
  end
end