Method: When::Parts::Enumerator#with_index

Defined in:
lib/when_exe/parts/enumerator.rb

#with_index(offset = 0, &block) ⇒ When::Parts:Enumerator

index をブロックに渡して評価する

Parameters:

  • offset (Integer) (defaults to: 0)

    index の初期値

Returns:

  • (When::Parts:Enumerator)
    ブロックあり - rewind された self
    ブロックなし - copy


126
127
128
129
130
131
132
133
134
135
136
# File 'lib/when_exe/parts/enumerator.rb', line 126

def with_index(offset=0, &block)
  if block_given?
    @index = offset||@count
    return each(block)
  else
    copy = _copy
    copy.object = nil
    copy.index  = offset||@count
    return copy
  end
end