Module: Iterable

Included in:
Array
Defined in:
lib/iterable.rb

Instance Method Summary collapse

Instance Method Details

#done?Boolean

TODO: consider a module inclusion time solution to “count rescue size”, for performance sake

Returns:

  • (Boolean)


22
23
24
# File 'lib/iterable.rb', line 22

def done?
  @next_index && (@next_index == (count rescue size)-1)
end

#nextObject



7
8
9
10
# File 'lib/iterable.rb', line 7

def next
  restart unless defined? @next_index
  raw_next
end

#raw_nextObject

Raises:

  • (RangeError)


12
13
14
15
# File 'lib/iterable.rb', line 12

def raw_next
  raise RangeError, 'there is no next element, please restart' if done?
  self[@next_index += 1]
end

#restartObject



2
3
4
5
# File 'lib/iterable.rb', line 2

def restart
  @next_index = -1
  self
end

#restart_and_raw_nextObject



17
18
19
# File 'lib/iterable.rb', line 17

def restart_and_raw_next
  self[@next_index = 0]
end