class PokerHands
Attributes
hands[RW]
Public Class Methods
new()
click to toggle source
# File lib/poker_hands.rb, line 20 def initialize @hands = [] end
Public Instance Methods
<<(hand)
click to toggle source
# File lib/poker_hands.rb, line 33 def <<(hand) @hands << hand end
winner()
click to toggle source
# File lib/poker_hands.rb, line 24 def winner sorted_hands = @hands.sort { |a, b| a.rank.class::SCORE <=> b.rank.class::SCORE } if sorted_hands.size > 1 && same_best_rank?(sorted_hands.reverse) find_winner_if_same_rank(sorted_hands.reverse) else sorted_hands.last end end
Private Instance Methods
find_winner_if_same_rank(sorted_hands)
click to toggle source
# File lib/poker_hands.rb, line 43 def find_winner_if_same_rank(sorted_hands) rank_class = sorted_hands.first.rank.class same_rank_hands = sorted_hands.select{|hand| hand.rank.class == rank_class} same_rank_hands.sort.last end
same_best_rank?(rank)
click to toggle source
# File lib/poker_hands.rb, line 39 def same_best_rank?(rank) rank[0].rank.class == rank[1].rank.class end