There are many ways to do this. I didn't solve it but started some basic classes you could add to structure game playing. I'd add a method in your Deck class that takes one card from the deck. Also a 'Player' class would be useful to represent each player. Each player object would have a hand attribute that holds the cards:
class Deck
def remove_card
self.cards.pop # removes a card from end of array
end
def empty?
self.cards.count == 0
end
end
d = Deck.new
d.cards.count #=> 52 cards
p = Player.new
p.hand << d.remove_card
d.cards.count #=> 51 cards now that one has been removed
Your deck holds the cards in an array. Your output is a string because you have it print out the ranks, but the card attribute is indeed an array holding card objects. You can also have a Game class that handles game play:
class Game
def initialize(player1, player2)
@player1 = player1
@player2 = player2
end
def play_poker
@deck = Deck.new
# give each player five cards
1.upto(5) do |num|
@player1.hand << @deck.remove_card
@player2.hand << @deck.remove_card
end
# each player has a five card hand at this point
# omitted code, have a method to score the two hands and determine the winner
end
def play_war
# omitted code, have players issued cards
# omitted, instructions, game play code
end
end
So you could have the game play different games. Scoring and output are other methods you would need to add. I also omitted the Player class for you to do. But you could play games like so:
p1 = Player.new
p2 = Player.new
game = Game.new(p1, p2)
game.play_poker #=> output could be text like: Player 1's hand: A, 4, 4, 2, Q, Player 2's hand:...... etc
#=> winner is Player 1!
Scoring could be done by a method in the game class. It would also output text like above printing the hand each player got and who won. If doing many games with the same game object, you'd have to make sure the players have their hands cleared, new decks are used (or make a reshuffle method) and so on.
If you actually want two people playing, you would have buttons control each step. H to hit or s to stay and so on. Hope this helps.