Class: Stream::ReversedStream
- Inherits:
-
WrappedStream
- Object
- BasicStream
- WrappedStream
- Stream::ReversedStream
- Defined in:
- lib/stream.rb
Overview
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]
Instance Attribute Summary
Attributes inherited from WrappedStream
Instance Method Summary collapse
-
#at_beginning? ⇒ Boolean
Returns true if the wrapped stream is at_end?.
-
#at_end? ⇒ Boolean
Returns true if the wrapped stream is at_beginning?.
-
#basic_backward ⇒ Object
Moves the wrapped stream one step forward.
-
#basic_forward ⇒ Object
Moves the wrapped stream one step backward.
-
#initialize(otherStream) ⇒ ReversedStream
constructor
Create a reversing wrapper for the reversable stream otherStream.
-
#set_to_begin ⇒ Object
Sets the wrapped stream to the end.
-
#set_to_end ⇒ Object
Sets the wrapped stream to the beginning.
Methods inherited from WrappedStream
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(otherStream) ⇒ ReversedStream
Create a reversing wrapper for the reversable stream otherStream. If otherStream does not support backward moving a NotImplementedError is signaled on the first backward move.
311 312 313 314 |
# File 'lib/stream.rb', line 311 def initialize (otherStream) super otherStream set_to_begin end |
Instance Method Details
#at_beginning? ⇒ Boolean
Returns true if the wrapped stream is at_end?.
317 |
# File 'lib/stream.rb', line 317 def at_beginning?; wrapped_stream.at_end?; end |
#at_end? ⇒ Boolean
Returns true if the wrapped stream is at_beginning?.
319 |
# File 'lib/stream.rb', line 319 def at_end?; wrapped_stream.at_beginning?; end |
#basic_backward ⇒ Object
Moves the wrapped stream one step forward.
324 |
# File 'lib/stream.rb', line 324 def basic_backward; wrapped_stream.basic_forward; end |
#basic_forward ⇒ Object
Moves the wrapped stream one step backward.
322 |
# File 'lib/stream.rb', line 322 def basic_forward; wrapped_stream.basic_backward; end |
#set_to_begin ⇒ Object
Sets the wrapped stream to the end.
329 |
# File 'lib/stream.rb', line 329 def set_to_begin; wrapped_stream.set_to_end; end |
#set_to_end ⇒ Object
Sets the wrapped stream to the beginning.
327 |
# File 'lib/stream.rb', line 327 def set_to_end; wrapped_stream.set_to_begin; end |