Class: Proc::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Is::Inspectable
Defined in:
lib/proc/enumerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, &next_block) ⇒ Enumerator

Returns a new instance of Enumerator.



14
15
16
17
# File 'lib/proc/enumerator.rb', line 14

def initialize(values, &next_block)
  @values = values
  @next_block = next_block
end

Instance Attribute Details

#next_blockObject (readonly)

Returns the value of attribute next_block.



12
13
14
# File 'lib/proc/enumerator.rb', line 12

def next_block
  @next_block
end

#valuesObject (readonly)

Returns the value of attribute values.



12
13
14
# File 'lib/proc/enumerator.rb', line 12

def values
  @values
end

Instance Method Details

#each(enumerable = self, &block) ⇒ Object

public

Calls the given block once for each value.



21
22
23
24
25
26
27
28
# File 'lib/proc/enumerator.rb', line 21

def each(enumerable = self, &block)
  return to_enum(:each) unless block

  while enumerable
    enumerable.values.each(&block)
    enumerable = enumerable.next_block&.call
  end
end