I'm looking to find all combinations of single items from a variable number of arrays. How do I do this in Ruby?
Given two arrays, I can use Array.product like this:
groups = []
groups[0] = ["hello", "goodbye"]
groups[1] = ["world", "everyone"]
combinations = groups[0].product(groups[1])
puts combinations.inspect
# [["hello", "world"], ["hello", "everyone"], ["goodbye", "world"], ["goodbye", "everyone"]]
How could this code work when groups contains a variable number of arrays?