Sha256: 293d87bb3b9a7cf1ca0fafa876789bd5a813b44875cd0b842f485c2cf295d436

Contents?: true

Size: 394 Bytes

Versions: 2

Compression:

Stored size: 394 Bytes

Contents

#from Design Patterns by Russ Olsen pg 128-129
module Shared
  class ArrayIterator
    def initialize(array)
      @array = array
      @index = 0
    end

    def has_next?
      @index < @array.length
    end

    def item
      @array[@index]
    end

    def peek
      @array[@index]
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
games_bfox-0.3.0 lib/games/shared/array_iterator.rb
games_bfox-0.2.0 lib/games/shared/array_iterator.rb