Class: Proc::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



9
10
11
12
# File 'lib/proc/enumerator.rb', line 9

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.



7
8
9
# File 'lib/proc/enumerator.rb', line 7

def next_block
  @next_block
end

#valuesObject (readonly)

Returns the value of attribute values.



7
8
9
# File 'lib/proc/enumerator.rb', line 7

def values
  @values
end

Instance Method Details

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

public

Calls the given block once for each value.



16
17
18
19
20
21
22
23
# File 'lib/proc/enumerator.rb', line 16

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

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