Module: Iterable
- Included in:
- Array
- Defined in:
- lib/iterable.rb
Instance Method Summary collapse
-
#done? ⇒ Boolean
TODO: consider a module inclusion time solution to “count rescue size”, for performance sake.
- #next ⇒ Object
- #raw_next ⇒ Object
- #restart ⇒ Object
- #restart_and_raw_next ⇒ Object
Instance Method Details
#done? ⇒ Boolean
TODO: consider a module inclusion time solution to “count rescue size”, for performance sake
22 23 24 |
# File 'lib/iterable.rb', line 22 def done? @next_index && (@next_index == (count rescue size)-1) end |
#next ⇒ Object
7 8 9 10 |
# File 'lib/iterable.rb', line 7 def next restart unless defined? @next_index raw_next end |
#raw_next ⇒ Object
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 |
#restart ⇒ Object
2 3 4 5 |
# File 'lib/iterable.rb', line 2 def restart @next_index = -1 self end |
#restart_and_raw_next ⇒ Object
17 18 19 |
# File 'lib/iterable.rb', line 17 def restart_and_raw_next self[@next_index = 0] end |