Class: Fried::Typings::EnumeratorOf

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

Overview

Checks if all enumerated objects Is of passed type

Instance Method Summary collapse

Methods included from Type

#<=>, #call, included

Methods included from MetaType

included

Constructor Details

#initialize(type) ⇒ EnumeratorOf

Returns a new instance of EnumeratorOf.



18
19
20
# File 'lib/fried/typings/enumerator_of.rb', line 18

def initialize(type)
  @type = type
end

Instance Method Details

#valid?(enumerator) ⇒ Boolean

Notice that the method will actually iterate over the enumerator

Parameters:

  • enumerator (Enumerator)

Returns:



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

def valid?(enumerator)
  return false unless Is[Enumerator].valid?(enumerator)

  enumerator.all? { |obj| Is[type].valid?(obj) }
end