Class: PokerHands::OnePair
- Defined in:
- lib/deck_of_cards_handler/poker_hands/one_pair.rb
Constant Summary
Constants inherited from PokerHand
Instance Attribute Summary collapse
-
#kickers ⇒ Object
readonly
Returns the value of attribute kickers.
-
#pair ⇒ Object
readonly
Returns the value of attribute pair.
Attributes inherited from PokerHand
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(cards:) ⇒ OnePair
constructor
A new instance of OnePair.
- #rank ⇒ Object
Methods inherited from PokerHand
Constructor Details
Instance Attribute Details
#kickers ⇒ Object (readonly)
Returns the value of attribute kickers.
18 19 20 |
# File 'lib/deck_of_cards_handler/poker_hands/one_pair.rb', line 18 def kickers @kickers end |
#pair ⇒ Object (readonly)
Returns the value of attribute pair.
15 16 17 |
# File 'lib/deck_of_cards_handler/poker_hands/one_pair.rb', line 15 def pair @pair end |
Class Method Details
.is?(cards) ⇒ Boolean
8 9 10 11 |
# File 'lib/deck_of_cards_handler/poker_hands/one_pair.rb', line 8 def is?(cards) counts = cards.map(&:rank).flatten.tally counts.values.count(2) == 1 end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/deck_of_cards_handler/poker_hands/one_pair.rb', line 33 def <=>(other) return rank <=> other.rank unless instance_of?(other.class) pair_comparison = pair_value <=> other.pair_value return pair_comparison unless pair_comparison.zero? kickers_value <=> other.kickers_value end |
#rank ⇒ Object
28 29 30 |
# File 'lib/deck_of_cards_handler/poker_hands/one_pair.rb', line 28 def rank 2 end |