Class: Holdem::PokerHand

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/holdem/poker_hand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards) ⇒ PokerHand

Returns a new instance of PokerHand.



15
16
17
18
# File 'lib/holdem/poker_hand.rb', line 15

def initialize(cards)
  @cards = cards.is_a?(String) ? CardGenerator.build(cards.split) : cards
  @poker_rank = PokerRank.new(@cards)
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



13
14
15
# File 'lib/holdem/poker_hand.rb', line 13

def cards
  @cards
end

#poker_rankObject (readonly)

Returns the value of attribute poker_rank.



13
14
15
# File 'lib/holdem/poker_hand.rb', line 13

def poker_rank
  @poker_rank
end

Instance Method Details

#<=>(other) ⇒ Object



24
25
26
# File 'lib/holdem/poker_hand.rb', line 24

def <=>(other)
  score <=> other.score
end

#countObject



20
21
22
# File 'lib/holdem/poker_hand.rb', line 20

def count
  cards.size
end

#just_cardsObject



28
29
30
# File 'lib/holdem/poker_hand.rb', line 28

def just_cards
  "#{cards.map{ |card| card.to_s }.join(' ')}"
end

#to_sObject



32
33
34
# File 'lib/holdem/poker_hand.rb', line 32

def to_s
  "#{just_cards} -> #{rank}"
end