Class: Shared::ArrayIterator
- Inherits:
-
Object
- Object
- Shared::ArrayIterator
- Defined in:
- lib/games/shared/array_iterator.rb
Instance Method Summary collapse
- #has_next? ⇒ Boolean
-
#initialize(array) ⇒ ArrayIterator
constructor
A new instance of ArrayIterator.
- #item ⇒ Object
- #next_item ⇒ Object
- #peek ⇒ Object
Constructor Details
#initialize(array) ⇒ ArrayIterator
4 5 6 7 |
# File 'lib/games/shared/array_iterator.rb', line 4 def initialize(array) @array = array @index = 0 end |
Instance Method Details
#has_next? ⇒ Boolean
9 10 11 |
# File 'lib/games/shared/array_iterator.rb', line 9 def has_next? @index < @array.length end |
#item ⇒ Object
13 14 15 |
# File 'lib/games/shared/array_iterator.rb', line 13 def item @array[@index] end |
#next_item ⇒ Object
21 22 23 24 25 |
# File 'lib/games/shared/array_iterator.rb', line 21 def next_item value = @array[@index] @index += 1 value end |
#peek ⇒ Object
17 18 19 |
# File 'lib/games/shared/array_iterator.rb', line 17 def peek @array[@index] end |