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



44
45
46
# File 'lib/backports/3.2.0/enumerator/product.rb', line 44

def initialize(*enums)
  @__enums = enums
end

Instance Method Details

#each(&block) ⇒ Object



50
51
52
53
54
# File 'lib/backports/3.2.0/enumerator/product.rb', line 50

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

#rewindObject



81
82
83
84
85
86
# File 'lib/backports/3.2.0/enumerator/product.rb', line 81

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

#sizeObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/backports/3.2.0/enumerator/product.rb', line 69

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