Skip to content

Instantly share code, notes, and snippets.

@keppy
Created May 29, 2012 23:06
Show Gist options
  • Save keppy/2831339 to your computer and use it in GitHub Desktop.
Save keppy/2831339 to your computer and use it in GitHub Desktop.
class PokerGame
include Enumerable
include Comparable
attr_reader :hand
def initialize(hands, cards)
ranks = %w{ 2 3 4 5 6 7 8 9 T J Q K A }
suits = %w{ S H D C }
card_stack = Array.new
h = Array.new
suits.each {|suit|
ranks.size.times {|i|
card_stack << (ranks[i]+suit)
}
}
card_stack.shuffle!
hands.times { |y| h << {}}
hands.times do |x| (cards * x).upto(cards*(x+1)) { |z| h << card_stack[z]}
end
puts h
end
end
PokerGame.new(2, 5)
# The current output is :
# {}
# {}
# KS
# 4D
# 9C
# 8D
# AH
# JC
# JC
# 2H
# 5S
# 4S
# 7S
# QD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment