Last Updated: February 25, 2016
·
1.289K
· felipeelias

Combine two arrays in ruby with #product

If you ever want to join two arrays by making a combination of each of the first array with the second use product:

gifts = ['candy', 'robot']
children = ['andy', 'carl', 'alice']
gifts.product children
# => [["candy", "andy"], ["candy", "carl"],
      ["candy", "alice"], ["robot", "andy"],
      ["robot", "carl"], ["robot", "alice"]]

All gifts to the children!!