Class: SequenceEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/utilrb/enumerable/sequence.rb
Overview
An enumerator which iterates on multiple iterators in sequence
([1, 2].enum_for + [2, 3].enum_for).to_a # => [1, 2, 2, 3]
See also Enumerable::Enumerator#+
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#<<(other) ⇒ Object
Adds
object
at the back of the sequence. - #each ⇒ Object
-
#initialize ⇒ SequenceEnumerator
constructor
A new instance of SequenceEnumerator.
Methods included from Enumerable
Constructor Details
#initialize ⇒ SequenceEnumerator
Returns a new instance of SequenceEnumerator.
9 |
# File 'lib/utilrb/enumerable/sequence.rb', line 9 def initialize; @sequence = Array.new end |
Instance Method Details
#+(other) ⇒ Object
11 |
# File 'lib/utilrb/enumerable/sequence.rb', line 11 def +(other); SequenceEnumerator.new << self << other end |
#<<(other) ⇒ Object
Adds object
at the back of the sequence
13 |
# File 'lib/utilrb/enumerable/sequence.rb', line 13 def <<(other); @sequence << other; self end |
#each ⇒ Object
15 16 17 18 |
# File 'lib/utilrb/enumerable/sequence.rb', line 15 def each @sequence.each { |enum| enum.each { |o| yield(o) } } if block_given? self end |