Skip to content

Instantly share code, notes, and snippets.

@tosik
Last active August 29, 2015 13:56
Show Gist options
  • Save tosik/9319629 to your computer and use it in GitHub Desktop.
Save tosik/9319629 to your computer and use it in GitHub Desktop.
module Poker
class Card
attr_accessor :number, :mark
def initialize(number, mark)
@number = number
@mark = mark
end
def number_string
case @number
when 1
"A"
when 11
"J"
when 12
"Q"
when 13
"K"
else
@number
end
end
def mark_string
case @mark
when :spade
"♠"
when :heart
"♥"
when :diamond
"♦"
when :club
"♣"
end
end
def to_s
"#{mark_string} #{number_string}"
end
end
class Hand
def initialize
@cards = [
Card.new(1, :spade),
Card.new(2, :heart),
Card.new(3, :diamond),
Card.new(3, :heart),
Card.new(2, :club),
]
end
def to_s
@cards.map {|card| card.to_s }.join(",")
end
def rank
count = 0
@cards.each do |left|
@cards.each do |top|
count += 1 if left.number == top.number
end
end
count
end
end
end
hand = Poker::Hand.new
puts hand
puts hand.rank
@tosik
Copy link
Author

tosik commented Mar 3, 2014

途中すぎる感じのコードですが、rubygems.org に poker gem があったので作るのやめた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment