Class: Shared::ArrayIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/games/shared/array_iterator.rb

Instance Method Summary collapse

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

#itemObject



13
14
15
# File 'lib/games/shared/array_iterator.rb', line 13

def item
  @array[@index]
end

#next_itemObject



21
22
23
24
25
# File 'lib/games/shared/array_iterator.rb', line 21

def next_item
  value = @array[@index]
  @index += 1
  value
end

#peekObject



17
18
19
# File 'lib/games/shared/array_iterator.rb', line 17

def peek
  @array[@index]
end