Crossjoin.rb

This content was produced by an LLM and could include errors.

This script demonstrates the Cartesian product using Array#product. It efficiently generates all possible combinations (tuples) by combining elements from three separate input arrays.

a = ('a'..'c').to_a
#=> ["a", "b", "c"]
b = 2.times.to_a
#=> [0, 1]
c = [{}]
#=> [{}]

a.product(b, c)
#=> [["a", 0, {}],
 ["a", 1, {}],
 ["b", 0, {}],
 ["b", 1, {}],
 ["c", 0, {}],
 ["c", 1, {}]]

Ruby 4.0.3