Skip to content

Instantly share code, notes, and snippets.

@CodePint
Created July 1, 2018 14:50
Show Gist options
  • Save CodePint/387537ac48ff46a84838a5b84800cebf to your computer and use it in GitHub Desktop.
Save CodePint/387537ac48ff46a84838a5b84800cebf to your computer and use it in GitHub Desktop.
class Hand
attr_accessor :cards, :highest_hand, :value
include Comparable
def initialize(cards:, highest_hand:)
@cards = cards
@highest_hand = highest_hand
end
def set_value(value)
@value = value
end
def <=>(other)
self.value <=> other.value
end
end
my_hand = Hand.new(cards: "TH JH QH KH AH", highest_hand: "royal_flush")
other_hand = Hand.new(cards: "TC TD KS KD 3C", highest_hand: "two_pair")
my_hand.set_value(10)
other_hand.set_value(3)
puts my_hand > other_hand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment