Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created January 21, 2009 00:26
Show Gist options
  • Save pragdave/49769 to your computer and use it in GitHub Desktop.
Save pragdave/49769 to your computer and use it in GitHub Desktop.
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