I'm coming to Ruby from Java and not really comfortable with it on the second day. What I'm doing is to initialize decks of cards with a given number of decks. Say I will be playing with 2 decks of cards, 52 cards in each deck, and thus 104 cards in total (Jokers are not used). My program goes:
def initialize(num)
@num_of_decks = num
# initialize my cards here...
end
After initialization, I want my cards to be:
cards = {"Diamond A", "Diamond 2", ... "Diamond K",
"Club A", ...
...
"Spade A", ... "Spade K", // end of the first deck
"Diamond A", ...
...
"Spade A", ... "Spade K" // end of the second deck
}
I want my program to be able to adapt to whatever num_of_decks is. I don't really have a clear feeling of how Ruby loops work by now, especially when it seems that for loops are discouraged in Ruby. Hopefully anyone can provide an example here so that I can study how it works.
[], hashes use{}.