xpmojw
Last Updated: February 25, 2016
·
890
· felipeelias
F6faa607e4f541da71fbf8aea6f99a7a

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!!

Say Thanks
Respond