Class: Stream::IntervalStream

### Home Classes Methods

### In Files

- lib/stream.rb

### Parent

Stream::BasicStream

### Methods

- ::new
- #at_beginning?
- #at_end?
- #basic_backward
- #basic_forward
- #increment_stop
- #set_to_begin
- #set_to_end

### Class/Module Index

Quicksearch

- Stream
- Stream::BasicStream
- Stream::CollectionStream
- Stream::ConcatenatedStream
- Stream::EmptyStream
- Stream::EndOfStreamException
- Stream::FilteredStream
- Stream::ImplicitStream
- Stream::IntervalStream
- Stream::MappedStream
- Stream::ReversedStream
- Stream::WrappedStream
- Array
- Enumerable
- Generator
- Object

No matching classes.

# 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, line 183
    def initialize (stop=0)
      @stop = stop - 1
      set_to_begin
    end

### Public Instance Methods

at_beginning?() click to toggle source

    # File lib/stream.rb, line 188
    def at_beginning?; @pos < 0; end

at_end?() click to toggle source

    # File lib/stream.rb, line 189
    def at_end?; @pos == @stop; end

basic_backward() click to toggle source

    # File lib/stream.rb, line 198
    def basic_backward;  @pos -= 1; @pos + 1; end

basic_forward() click to toggle source

    # File lib/stream.rb, line 197
    def basic_forward; @pos += 1; end

increment_stop(incr=1) click to toggle source

Increment the upper bound by incr.

    # File lib/stream.rb, line 195
    def increment_stop (incr=1); @stop += incr; end

set_to_begin() click to toggle source

    # File lib/stream.rb, line 192
    def set_to_begin; @pos = -1; end

set_to_end() click to toggle source

    # File lib/stream.rb, line 191
    def set_to_end; @pos = @stop; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.