Class: PokerHands::Straight
- Inherits:
-
PokerHand
show all
- Defined in:
- lib/deck_of_cards_handler/poker_hands/straight.rb
Constant Summary
Constants inherited
from PokerHand
PokerHand::HANDS
Instance Attribute Summary
Attributes inherited from PokerHand
#cards
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PokerHand
build_from_string, create, #initialize
Class Method Details
.is?(cards) ⇒ Boolean
8
9
10
11
12
13
14
|
# File 'lib/deck_of_cards_handler/poker_hands/straight.rb', line 8
def is?(cards)
ranks = cards.map(&:rank).sort
return true if ranks.each_cons(2).all? { |a, b| b == T.must(a) + 1 }
ranks = cards.map { _1.rank(low_ace: true) }.sort
ranks.each_cons(2).all? { |a, b| b == T.must(a) + 1 }
end
|
Instance Method Details
#<=>(other) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/deck_of_cards_handler/poker_hands/straight.rb', line 23
def <=>(other)
return rank <=> other.rank unless instance_of?(other.class)
c1 = cards.map { card_value(_1) }
c2 = other.cards.map { other.card_value(_1) }
c1 <=> c2
end
|
#rank ⇒ Object
18
19
20
|
# File 'lib/deck_of_cards_handler/poker_hands/straight.rb', line 18
def rank
5
end
|