Class: Stream::IntervalStream
- Inherits:
-
BasicStream
- Object
- BasicStream
- Stream::IntervalStream
- Defined in:
- lib/stream.rb
Overview
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.
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
- #at_beginning? ⇒ Boolean
- #at_end? ⇒ Boolean
- #basic_backward ⇒ Object
- #basic_forward ⇒ Object
-
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
-
#initialize(stop = 0) ⇒ IntervalStream
constructor
Create a new IntervalStream with upper bound stop.
- #set_to_begin ⇒ Object
- #set_to_end ⇒ Object
Methods included from Stream
#+, #backward, #collect, #concatenate, #concatenate_collected, #create_stream, #current, #current_edge, #each, #empty?, #filtered, #first, #forward, #last, #modify, #move_backward_until, #move_forward_until, #peek, #remove_first, #remove_last, #reverse, #unwrapped
Methods included from Enumerable
Constructor Details
#initialize(stop = 0) ⇒ IntervalStream
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.
186 187 188 189 |
# File 'lib/stream.rb', line 186 def initialize(stop=0) @stop = stop - 1 set_to_begin end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
182 183 184 |
# File 'lib/stream.rb', line 182 def pos @pos end |
Instance Method Details
#at_beginning? ⇒ Boolean
191 |
# File 'lib/stream.rb', line 191 def at_beginning?; @pos < 0; end |
#at_end? ⇒ Boolean
192 |
# File 'lib/stream.rb', line 192 def at_end?; @pos == @stop; end |
#basic_backward ⇒ Object
201 |
# File 'lib/stream.rb', line 201 def basic_backward; @pos -= 1; @pos + 1; end |
#basic_forward ⇒ Object
200 |
# File 'lib/stream.rb', line 200 def basic_forward; @pos += 1; end |
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
198 |
# File 'lib/stream.rb', line 198 def increment_stop(incr=1); @stop += incr; end |
#set_to_begin ⇒ Object
195 |
# File 'lib/stream.rb', line 195 def set_to_begin; @pos = -1; end |
#set_to_end ⇒ Object
194 |
# File 'lib/stream.rb', line 194 def set_to_end; @pos = @stop; end |