Class: Enumerator::Chain
Instance Method Summary
collapse
Methods inherited from Enumerator
#initialize_with_optional_block, produce, product
Constructor Details
#initialize(*enums) ⇒ Chain
Returns a new instance of Chain.
12
13
14
15
16
17
18
19
|
# File 'lib/backports/2.6.0/enumerable/chain.rb', line 12
def initialize(*enums)
@enums = enums
@rewindable = -1
self end
|
Instance Method Details
#each(*args, &block) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/backports/2.6.0/enumerable/chain.rb', line 22
def each(*args, &block)
@enums.each_with_index do |enum, i|
@rewindable = i
enum.each(*args, &block)
end
end
|
39
40
41
42
|
# File 'lib/backports/2.6.0/enumerable/chain.rb', line 39
def inspect
detail = @enums.map(&:inspect).join(', ')
"#<Enumerator::Chain: [#{detail}]>"
end
|
44
45
46
47
48
49
50
|
# File 'lib/backports/2.6.0/enumerable/chain.rb', line 44
def rewind
@rewindable.downto(0) do |i|
enum = @enums[i]
enum.rewind if enum.respond_to? :rewind
end
self
end
|
29
30
31
32
33
34
35
36
37
|
# File 'lib/backports/2.6.0/enumerable/chain.rb', line 29
def size
sum = 0
@enums.each do |enum|
s = enum.size
return s if s == nil || s == Float::INFINITY
sum += s
end
sum
end
|