Class: Enumerator.self::Chain

Inherits:
Enumerator
  • Object
show all
Defined in:
opal/opal/corelib/enumerator/chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(*enums) ⇒ Chain

Returns a new instance of Chain.



3
4
5
6
7
# File 'opal/opal/corelib/enumerator/chain.rb', line 3

def initialize(*enums)
  @enums = enums
  @iterated = []
  @object = self
end

Instance Method Details

#each(*args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'opal/opal/corelib/enumerator/chain.rb', line 9

def each(*args, &block)
  return to_enum(:each, *args) { size } unless block_given?

  @enums.each do |enum|
    @iterated << enum
    enum.each(*args, &block)
  end

  self
end

#inspectObject



38
39
40
# File 'opal/opal/corelib/enumerator/chain.rb', line 38

def inspect
  "#<Enumerator::Chain: #{@enums.inspect}>"
end

#rewindObject



30
31
32
33
34
35
36
# File 'opal/opal/corelib/enumerator/chain.rb', line 30

def rewind
  @iterated.reverse_each do |enum|
    enum.rewind if enum.respond_to? :rewind
  end
  @iterated = []
  self
end

#size(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'opal/opal/corelib/enumerator/chain.rb', line 20

def size(*args)
  accum = 0
  @enums.each do |enum|
    size = enum.size(*args)
    return size if [nil, ::Float::INFINITY].include? size
    accum += size
  end
  accum
end