Class Stream::ImplicitStream
In: lib/stream.rb
Parent: BasicStream

An ImplicitStream is an easy way to create a stream on the fly without defining a subclass of BasicStream. The basic methods required for a stream are defined with blocks:

 s = Stream::ImplicitStream.new { |s|
            x = 0
            s.at_end_proc = proc {x == 5}
            s.forward_proc = proc {x += 1 }
     }

 s.to_a ==> [1, 2, 3, 4, 5]

Note that this stream is only partially defined since backward_proc and at_beginning_proc are not defined. It may as well be useful if only moving forward is required by the code fragment.

ImplicitStreams can be based on other streams using the method modify which is for example used in the methods for creating stream wrappers which remove the first or last element of an existing stream (see remove_first and remove_last).

Methods

Attributes

at_beginning_proc  [W] 
at_end_proc  [W] 
backward_proc  [W] 
forward_proc  [W] 
set_to_begin_proc  [W] 
set_to_end_proc  [W] 
wrapped_stream  [R] 

Public Class methods

Create a new ImplicitStream which might wrap an existing stream otherStream. If otherStream is supplied the blocks for the basic stream methods are initialized with closures that delegate all operations to the wrapped stream.

If a block is given to new, than it is called with the new ImplicitStream stream as parameter letting the client overwriting the default blocks.

Public Instance methods

Returns the value of @at_beginning_proc.

Returns the value of @at_end_proc.

Returns the value of @backward_proc_proc.

Returns the value of @forward_proc.

Calls set_to_begin_proc or super if set_to_begin_proc is undefined.

Calls set_to_end_proc or super if set_to_end_proc is undefined.

[Validate]