Class: PokerHands::TwoPairs
- Defined in:
- lib/deck_of_cards_handler/poker_hands/two_pairs.rb
Constant Summary
Constants inherited from PokerHand
Instance Attribute Summary collapse
-
#kicker ⇒ Object
readonly
Returns the value of attribute kicker.
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
Attributes inherited from PokerHand
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(cards:) ⇒ TwoPairs
constructor
A new instance of TwoPairs.
- #rank ⇒ Object
Methods inherited from PokerHand
Constructor Details
#initialize(cards:) ⇒ TwoPairs
Returns a new instance of TwoPairs.
13 14 15 16 17 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 13 def initialize(cards:) super @pairs = T.let(extract_pairs, T::Array[Card]) @kicker = T.let(extract_kicker, T::Array[Card]) end |
Instance Attribute Details
#kicker ⇒ Object (readonly)
Returns the value of attribute kicker.
10 11 12 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 10 def kicker @kicker end |
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
7 8 9 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 7 def pairs @pairs end |
Class Method Details
.is?(cards) ⇒ Boolean
39 40 41 42 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 39 def is?(cards) counts = cards.map(&:rank).flatten.tally counts.values.count(2) == 2 end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 25 def <=>(other) return rank <=> other.rank unless instance_of?(other.class) first_pair_comparison = pair_values.first <=> other.pair_values.first return first_pair_comparison unless T.must(first_pair_comparison).zero? second_pair_comparison = pair_values.last <=> other.pair_values.last return second_pair_comparison unless T.must(second_pair_comparison).zero? kickers_value <=> other.kickers_value end |
#rank ⇒ Object
20 21 22 |
# File 'lib/deck_of_cards_handler/poker_hands/two_pairs.rb', line 20 def rank 3 end |