class Stream::CollectionStream
A CollectionStream
can be used as an external iterator for each interger-indexed collection. The state of the iterator is stored in instance variable @pos.
A CollectionStream
for an array is created by the method Array#create_stream
.
Attributes
Public Class Methods
Source
# File lib/stream.rb 195 def initialize(seq) 196 @seq = seq 197 set_to_begin 198 end
Creates a new CollectionStream
for the indexable sequence seq.
Public Instance Methods
Source
# File lib/stream.rb 223 def basic_backward 224 r = @seq[@pos] 225 @pos -= 1; r 226 end
Source
# File lib/stream.rb 218 def basic_forward 219 @pos += 1 220 @seq[@pos] 221 end
Protected Instance Methods
Source
# File lib/stream.rb 232 def basic_current 233 @seq[@pos] 234 end
basic_current
and basic_peek
can be implemented more efficiently than in superclass