class Fried::Typings::TupleOf

Checks if Array fields match types specified on a 1-to-1 relationship. So `[123, “test”, nil]` matches `TupleOf[Numeric, String, NilClass]`

Attributes

types[R]

Public Class Methods

new(*types) click to toggle source
# File lib/fried/typings/tuple_of.rb, line 19
def initialize(*types)
  @types = types
end

Public Instance Methods

valid?(ary) click to toggle source
# File lib/fried/typings/tuple_of.rb, line 23
def valid?(ary)
  return false unless ary.size == types.size

  types.each.with_index.all? do |type, index|
    Is[type].valid?(ary[index])
  end
end