Class: Fried::Typings::TupleOf
- Inherits:
-
Object
- Object
- Fried::Typings::TupleOf
- Defined in:
- lib/fried/typings/tuple_of.rb
Overview
Checks if Array fields match types specified on a 1-to-1 relationship. So ‘[123, “test”, nil]` matches `TupleOf[Numeric, String, NilClass]`
Instance Method Summary collapse
-
#initialize(*types) ⇒ TupleOf
constructor
A new instance of TupleOf.
- #valid?(ary) ⇒ Boolean
Methods included from Type
Methods included from MetaType
Constructor Details
#initialize(*types) ⇒ TupleOf
19 20 21 |
# File 'lib/fried/typings/tuple_of.rb', line 19 def initialize(*types) @types = types end |
Instance Method Details
#valid?(ary) ⇒ Boolean
23 24 25 26 27 28 29 |
# 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 |