Class: Fried::Typings::ArrayOf

Inherits:
Object
  • Object
show all
Includes:
MetaType, Type
Defined in:
lib/fried/typings/array_of.rb

Overview

Checks if all elements of the array match given type

Instance Method Summary collapse

Methods included from Type

#<=>, #call, included

Methods included from MetaType

included

Constructor Details

#initialize(type) ⇒ ArrayOf

Returns a new instance of ArrayOf.



19
20
21
# File 'lib/fried/typings/array_of.rb', line 19

def initialize(type)
  @type = type
end

Instance Method Details

#valid?(ary) ⇒ Boolean

Parameters:

  • ary (Array)

Returns:



24
25
26
27
28
29
30
# File 'lib/fried/typings/array_of.rb', line 24

def valid?(ary)
  return false unless Is[Array].valid?(ary)

  enumerator = ary.each

  EnumeratorOf[type].valid?(enumerator)
end