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 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(other_stream) ⇒ ReversedStream
constructor
Create a reversing wrapper for the reversable stream other_stream.
-
#set_to_begin ⇒ Object
Sets the wrapped stream to the end.
-
#set_to_end ⇒ Object
Sets the wrapped stream to the beginning.
Constructor Details
#initialize(other_stream) ⇒ ReversedStream
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.
421 422 423 424 |
# File 'lib/stream.rb', line 421 def initialize(other_stream) super other_stream set_to_begin end |
Instance Method Details
#at_beginning? ⇒ Boolean
Returns true if the wrapped stream is at_end?.
427 428 429 |
# File 'lib/stream.rb', line 427 def at_beginning? wrapped_stream.at_end? end |
#at_end? ⇒ Boolean
Returns true if the wrapped stream is at_beginning?.
432 433 434 |
# File 'lib/stream.rb', line 432 def at_end? wrapped_stream.at_beginning? end |
#basic_backward ⇒ Object
Moves the wrapped stream one step forward.
442 443 444 |
# File 'lib/stream.rb', line 442 def basic_backward wrapped_stream.basic_forward end |
#basic_forward ⇒ Object
Moves the wrapped stream one step backward.
437 438 439 |
# File 'lib/stream.rb', line 437 def basic_forward wrapped_stream.basic_backward end |
#set_to_begin ⇒ Object
Sets the wrapped stream to the end.
452 453 454 |
# File 'lib/stream.rb', line 452 def set_to_begin wrapped_stream.set_to_end end |
#set_to_end ⇒ Object
Sets the wrapped stream to the beginning.
447 448 449 |
# File 'lib/stream.rb', line 447 def set_to_end wrapped_stream.set_to_begin end |