class Stream::ReversedStream

Each reversable stream (a stream that implements backward and at_beginning?) can be wrapped by a ReversedStream.

A ReversedStream is created by the method reverse:

(1..6).create_stream.reverse.to_a ==> [6, 5, 4, 3, 2, 1]

Public Class Methods

new(other_stream) click to toggle source

Create a reversing wrapper for the reversable stream other_stream. If other_stream does not support backward moving a NotImplementedError is signaled on the first backward move.

Calls superclass method Stream::WrappedStream::new
    # File lib/stream.rb
421 def initialize(other_stream)
422   super other_stream
423   set_to_begin
424 end

Public Instance Methods

at_beginning?() click to toggle source

Returns true if the wrapped stream is at_end?.

    # File lib/stream.rb
427 def at_beginning?
428   wrapped_stream.at_end?
429 end
at_end?() click to toggle source

Returns true if the wrapped stream is at_beginning?.

    # File lib/stream.rb
432 def at_end?
433   wrapped_stream.at_beginning?
434 end
basic_backward() click to toggle source

Moves the wrapped stream one step forward.

    # File lib/stream.rb
442 def basic_backward
443   wrapped_stream.basic_forward
444 end
basic_forward() click to toggle source

Moves the wrapped stream one step backward.

    # File lib/stream.rb
437 def basic_forward
438   wrapped_stream.basic_backward
439 end
set_to_begin() click to toggle source

Sets the wrapped stream to the end.

    # File lib/stream.rb
452 def set_to_begin
453   wrapped_stream.set_to_end
454 end
set_to_end() click to toggle source

Sets the wrapped stream to the beginning.

    # File lib/stream.rb
447 def set_to_end
448   wrapped_stream.set_to_begin
449 end