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!!
Written by Felipe Elias Philipp
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#