class Enumerator::Product

Enumerator::Product 生成任意数量可枚举对象的笛卡尔积。遍历可枚举对象的乘积大致相当于嵌套的 each_entry 循环,其中最右侧对象的循环放在最内层。

innings = Enumerator::Product.new(1..9, ['top', 'bottom'])

innings.each do |i, h|
  p [i, h]
end
# [1, "top"]
# [1, "bottom"]
# [2, "top"]
# [2, "bottom"]
# [3, "top"]
# [3, "bottom"]
# ...
# [9, "top"]
# [9, "bottom"]

针对每个可枚举对象使用的方法是 'each_entry' 而不是 'each',以便 N 个可枚举对象的乘积在每次迭代中产生一个恰好包含 N 个元素的数组。

当没有给出枚举器时,它会调用给定的块一次,产生一个空参数列表。

这类对象可以通过 Enumerator.product 创建。