Class: Enumerator::Product

Inherits:
Enumerator show all
Defined in:
lib/backports/3.2.0/enumerator/product.rb

Instance Method Summary collapse

Methods inherited from Enumerator

#initialize_with_optional_block, produce, product

Constructor Details

#initialize(*enums) ⇒ Product

rubocop:disable Lint/MissingSuper



30
31
32
# File 'lib/backports/3.2.0/enumerator/product.rb', line 30

def initialize(*enums)
  @__enums = enums
end

Instance Method Details

#each(&block) ⇒ Object



36
37
38
39
# File 'lib/backports/3.2.0/enumerator/product.rb', line 36

def each(&block)
  return self unless block
  __execute(block, [], @__enums)
end

#rewindObject



66
67
68
69
70
71
# File 'lib/backports/3.2.0/enumerator/product.rb', line 66

def rewind
  @__enums.each do |enum|
    enum.rewind if enum.respond_to?(:rewind)
  end
  self
end

#sizeObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/backports/3.2.0/enumerator/product.rb', line 54

def size
  total_size = 1
  @__enums.each do |enum|
    return nil unless enum.respond_to?(:size)
    size = enum.size
    return size if size == nil || size == Float::INFINITY || size == 0
    return nil unless size.is_a?(Integer)
    total_size *= size
  end
  total_size
end