class Stream::IntervalStream
A simple Iterator for iterating over a sequence of integers starting from zero up to a given upper bound. Mainly used by Stream::FilteredStream
. Could be made private but if somebody needs it here it is. Is there a better name for it?
The upper bound is stored in the instance variable @stop which can be incremented dynamically by the method increment_stop.
Attributes
pos[R]
Public Class Methods
new(stop = 0)
click to toggle source
Create a new IntervalStream
with upper bound stop. stop - 1 is the last element. By default stop is zero which means that the stream is empty.
# File lib/stream.rb 255 def initialize(stop = 0) 256 @stop = stop - 1 257 set_to_begin 258 end
Public Instance Methods
at_beginning?()
click to toggle source
# File lib/stream.rb 260 def at_beginning? 261 @pos < 0 262 end
at_end?()
click to toggle source
# File lib/stream.rb 264 def at_end? 265 @pos == @stop 266 end
basic_backward()
click to toggle source
# File lib/stream.rb 285 def basic_backward 286 @pos -= 1 287 @pos + 1 288 end
basic_forward()
click to toggle source
# File lib/stream.rb 281 def basic_forward 282 @pos += 1 283 end
increment_stop(incr = 1)
click to toggle source
Increment the upper bound by incr.
# File lib/stream.rb 277 def increment_stop(incr = 1) 278 @stop += incr 279 end
set_to_begin()
click to toggle source
# File lib/stream.rb 272 def set_to_begin 273 @pos = -1 274 end
set_to_end()
click to toggle source
# File lib/stream.rb 268 def set_to_end 269 @pos = @stop 270 end