Class: TexasHoldem::Combinations::Combination
- Inherits:
-
Object
- Object
- TexasHoldem::Combinations::Combination
- Includes:
- Comparable
- Defined in:
- lib/texas-holdem/combinations/combination.rb
Direct Known Subclasses
Constant Summary collapse
- MAX_COMBINATION_LENGTH =
5
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#cards_by_rank ⇒ Object
readonly
Returns the value of attribute cards_by_rank.
-
#cards_by_suit ⇒ Object
readonly
Returns the value of attribute cards_by_suit.
-
#combination_cards ⇒ Object
readonly
Returns the value of attribute combination_cards.
-
#kicker_cards ⇒ Object
readonly
Returns the value of attribute kicker_cards.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #has_combination? ⇒ Boolean
-
#initialize(cards) ⇒ Combination
constructor
A new instance of Combination.
- #to_s ⇒ Object
Constructor Details
#initialize(cards) ⇒ Combination
Returns a new instance of Combination.
9 10 11 12 13 14 15 |
# File 'lib/texas-holdem/combinations/combination.rb', line 9 def initialize(cards) @cards = cards @cards_by_rank = get_cards_by_rank @cards_by_suit = get_cards_by_suit @combination_cards = get_combination_cards(cards) @kicker_cards = get_kicker_cards end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
7 8 9 |
# File 'lib/texas-holdem/combinations/combination.rb', line 7 def cards @cards end |
#cards_by_rank ⇒ Object (readonly)
Returns the value of attribute cards_by_rank.
7 8 9 |
# File 'lib/texas-holdem/combinations/combination.rb', line 7 def cards_by_rank @cards_by_rank end |
#cards_by_suit ⇒ Object (readonly)
Returns the value of attribute cards_by_suit.
7 8 9 |
# File 'lib/texas-holdem/combinations/combination.rb', line 7 def cards_by_suit @cards_by_suit end |
#combination_cards ⇒ Object (readonly)
Returns the value of attribute combination_cards.
7 8 9 |
# File 'lib/texas-holdem/combinations/combination.rb', line 7 def combination_cards @combination_cards end |
#kicker_cards ⇒ Object (readonly)
Returns the value of attribute kicker_cards.
7 8 9 |
# File 'lib/texas-holdem/combinations/combination.rb', line 7 def kicker_cards @kicker_cards end |
Instance Method Details
#<=>(other) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/texas-holdem/combinations/combination.rb', line 21 def <=>(other) compared_by_rank = RANKS[self.class] <=> RANKS[other.class] return compared_by_rank unless compared_by_rank == 0 compared_by_same_rank = compare_same_rank(other) return compared_by_same_rank unless compared_by_same_rank == 0 compare_kickers(other) end |
#has_combination? ⇒ Boolean
17 18 19 |
# File 'lib/texas-holdem/combinations/combination.rb', line 17 def has_combination? combination_cards.length > 0 end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/texas-holdem/combinations/combination.rb', line 29 def to_s "#{combination_cards.map(&:to_s)}, kickers: #{kicker_cards.map(&:to_s)}" end |