Class: ArrayIterator
- Inherits:
-
Object
- Object
- ArrayIterator
- Defined in:
- lib/marvelous_iterator/array_iterator.rb
Direct Known Subclasses
Instance Method Summary collapse
- #has_next? ⇒ Boolean
-
#initialize(array) ⇒ ArrayIterator
constructor
A new instance of ArrayIterator.
- #item ⇒ Object
- #next_item ⇒ Object
Constructor Details
#initialize(array) ⇒ ArrayIterator
Returns a new instance of ArrayIterator.
2 3 4 5 |
# File 'lib/marvelous_iterator/array_iterator.rb', line 2 def initialize(array) @array = array @index = 0 end |
Instance Method Details
#has_next? ⇒ Boolean
7 8 9 |
# File 'lib/marvelous_iterator/array_iterator.rb', line 7 def has_next? @index < @array.length end |
#item ⇒ Object
11 12 13 |
# File 'lib/marvelous_iterator/array_iterator.rb', line 11 def item @array[@index] end |
#next_item ⇒ Object
15 16 17 18 19 |
# File 'lib/marvelous_iterator/array_iterator.rb', line 15 def next_item value = @array[@index] @index += 1 value end |