Created
January 21, 2009 00:26
-
-
Save pragdave/49769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Card = Struct.new(:rank, :suit) | |
dealer = Fiber.new do | |
ranks = (1..13).to_a | |
suits = [:club, :diamond, :heart, :spade] | |
pack = ranks.product(suits).map {|card| Card.new(*card)} | |
all_cards = pack*7 | |
cards = [] | |
loop do | |
cards = all_cards.shuffle if cards.size < 2*52 | |
Fiber.yield cards.pop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment