I have two arrays:
array1: [[1, 2], [2, 3]]
array2: ["a", "b", "c"]
I would like to combine those two and get the below result:
[[1, 2, "a"], [1, 2, "b"], [1, 2, "c"], [2, 3, "a"], [2, 3, "b"], [2, 3, "c"]]
You can use Array#product:
array1.product(array2).map &:flatten
#=> [[1, 2, "a"], [1, 2, "b"], [1, 2, "c"], [2, 3, "a"], [2, 3, "b"], [2, 3, "c"]]
Array#product is purpose-built for this, but this is one alternative:
array2.flat_map { |e| array1.map { |arr| arr+[e] } }