The main problem here is that the state machine probably does not belong to your CardGame class. The state of the game lies elsewhere. There are four main domain models that I can see:
A Game will have one or more Decks (each of 52 Cards ) and one or more Hands . (You might even want to have a Player class where the player has-a Hand , your call).
As an example, Deck will probably have a shuffle! method shuffle! and deal . A Hand will have a play method. This may be the rule logic.
The Game class will consist mainly of a loop, such as:
def run deal do play_hands check_for_winner while(playing) end
More devil in the details, of course, but you may find this approach more refreshing and easier to test.
source share