Class: PokerHands::FourOfAKind
- Defined in:
- lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb
Constant Summary
Constants inherited from PokerHand
Instance Attribute Summary collapse
-
#four_of_a_kind ⇒ Object
readonly
Returns the value of attribute four_of_a_kind.
-
#kicker ⇒ Object
readonly
Returns the value of attribute kicker.
Attributes inherited from PokerHand
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(cards:) ⇒ FourOfAKind
constructor
A new instance of FourOfAKind.
- #rank ⇒ Object
Methods inherited from PokerHand
Constructor Details
#initialize(cards:) ⇒ FourOfAKind
Returns a new instance of FourOfAKind.
21 22 23 24 25 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 21 def initialize(cards:) super @four_of_a_kind = T.let(extract_four_of_a_kind, T::Array[Card]) @kicker = T.let(extract_kicker, T::Array[Card]) end |
Instance Attribute Details
#four_of_a_kind ⇒ Object (readonly)
Returns the value of attribute four_of_a_kind.
15 16 17 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 15 def four_of_a_kind @four_of_a_kind end |
#kicker ⇒ Object (readonly)
Returns the value of attribute kicker.
18 19 20 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 18 def kicker @kicker end |
Class Method Details
.is?(cards) ⇒ Boolean
8 9 10 11 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 8 def is?(cards) counts = cards.map(&:rank).flatten.tally counts.values.count(4) == 1 end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 33 def <=>(other) return rank <=> other.rank unless instance_of?(other.class) comparison = four_of_a_kind_value <=> other.four_of_a_kind_value return comparison unless comparison.zero? kicker_value <=> other.kicker_value end |
#rank ⇒ Object
28 29 30 |
# File 'lib/deck_of_cards_handler/poker_hands/four_of_a_kind.rb', line 28 def rank 8 end |