TuneUp: Poker- Reading the code base


This is a review of the Poker code base for TuneUp: Poker. The main post for this challenge can be found here

For an explanation of TuneUps you can find it here


Noticing the classes

Luckily, this is a small file and the first thing I notice is there are a few classes:

Breaking down Poker#best_hand

# Looking at the method

def best_hand
  # TODO: Your mission, should you choose to accept it,
  # refactor `Poker#best_hand` in a way that would be more sensible.
  best_hands = best_ranked_hands
  highest_card_value = 0
  best_hands.each do |hand|
    high_hand_value = hand.max_card_value
    if high_hand_value > highest_card_value
      highest_card_value = high_hand_value
    end
  end
  best_hands.select { |hand| hand.max_card_value == highest_card_value }
            .map(&:input)
end

Starting a refactor proposal

Should sorting be part of Poker?

Ruby sorting arrays

Clearing up Ranking


  def four_of_a_kind_values
    four_of_a_kind_value = cards_repeated_n_times(4)
    single_card_value    = cards_repeated_n_times(1)
    [four_of_a_kind_value, single_card_value].flatten
  end

Moving On