Class: PokerHands::FullHouse

Inherits:
PokerHand show all
Defined in:
lib/deck_of_cards_handler/poker_hands/full_house.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:) ⇒ FullHouse

Returns a new instance of FullHouse.



20
21
22
23
24
# File 'lib/deck_of_cards_handler/poker_hands/full_house.rb', line 20

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

Instance Attribute Details

#pairObject (readonly)

Returns the value of attribute pair.



17
18
19
# File 'lib/deck_of_cards_handler/poker_hands/full_house.rb', line 17

def pair
  @pair
end

#three_of_a_kindObject (readonly)

Returns the value of attribute three_of_a_kind.



14
15
16
# File 'lib/deck_of_cards_handler/poker_hands/full_house.rb', line 14

def three_of_a_kind
  @three_of_a_kind
end

Class Method Details

.is?(cards) ⇒ Boolean

Returns:

  • (Boolean)


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

def is?(cards)
  PokerHands::ThreeOfAKind.is?(cards) && PokerHands::OnePair.is?(cards)
end

Instance Method Details

#<=>(other) ⇒ Object



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

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?

  pair_value <=> other.pair_value
end

#rankObject



27
28
29
# File 'lib/deck_of_cards_handler/poker_hands/full_house.rb', line 27

def rank
  7
end