Class: PokerHands::ThreeOfAKind

Inherits:
PokerHand show all
Defined in:
lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb

Constant Summary

Constants inherited from PokerHand

PokerHand::HANDS

Instance Attribute Summary collapse

Attributes inherited from PokerHand

#cards

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PokerHand

build_from_string, create

Constructor Details

#initialize(cards:) ⇒ ThreeOfAKind

Returns a new instance of ThreeOfAKind.



21
22
23
24
25
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 21

def initialize(cards:)
  super
  @three_of_a_kind = T.let(extract_three_of_a_kind, T::Array[Card])
  @kickers = T.let(extract_kickers, T::Array[Card])
end

Instance Attribute Details

#kickersObject (readonly)

Returns the value of attribute kickers.



18
19
20
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 18

def kickers
  @kickers
end

#three_of_a_kindObject (readonly)

Returns the value of attribute three_of_a_kind.



15
16
17
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 15

def three_of_a_kind
  @three_of_a_kind
end

Class Method Details

.is?(cards) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 8

def is?(cards)
  counts = cards.map(&:rank).flatten.tally
  counts.values.count(3) == 1
end

Instance Method Details

#<=>(other) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 33

def <=>(other)
  return rank <=> other.rank unless instance_of?(other.class)

  comparison = three_of_a_kind_value <=> other.three_of_a_kind_value
  return comparison unless comparison.zero?

  kickers_value <=> other.kickers_value
end

#rankObject



28
29
30
# File 'lib/deck_of_cards_handler/poker_hands/three_of_a_kind.rb', line 28

def rank
  4
end