Class: Typeguard::Validation::Fixed

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

Instance Method Summary collapse

Methods inherited from Base

from

Constructor Details

#initialize(node) ⇒ Fixed

Returns a new instance of Fixed.



66
67
68
69
# File 'lib/typeguard/types.rb', line 66

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

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
# File 'lib/typeguard/types.rb', line 71

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

  @children.each_with_index.all? do |child, i|
    child.valid?(value[i])
  end
end