I want to make an array with every card in the deck, so it would be [“Ac”, “Ad”, “Ah”, “As”, “Kc”, …] though order is not important.
Isn’t there a way that inject could be used to solve this problem? This was as close as I could get.
cards = ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2"]
suits = ["c", "s", "d", "h"]
ruby-1.9.2-p180 :025 > cards.inject(suits) { |suit, card| suit.map{|s| "#{card}#{s}"}}
=> ["23456789TJQKAc", "23456789TJQKAs", "23456789TJQKAd", "23456789TJQKAh"]
Is this what you aim to do?