Permalink
Browse files

extract duplicate code out to public method

  • Loading branch information...
camillebaldock committed Sep 3, 2014
1 parent 2159bec commit 87d156a966ee998ba23e6bf2834e99b9cd2082d4
Showing with 8 additions and 10 deletions.
  1. +8 −10 lib/hand.rb
View
@@ -39,19 +39,17 @@ def rank
##bob
def pip_count
- pips = cards.map(&:pips)
- grouped_cards = pips.group_by { |i| i }
- grouped_cards.each do |key, value|
- grouped_cards[key] = value.count
- end
+ value_occurence_count(cards.map(&:pips))
end
- ##DUPE! pip_count
def suit_count
- suits = cards.map(&:suit)
- grouped_cards = suits.group_by { |i| i }
- grouped_cards.each do |key, value|
- grouped_cards[key] = value.count
+ value_occurence_count(cards.map(&:suit))
+ end
+
+ def value_occurence_count(array)
+ grouped_values = array.group_by { |i| i }
+ grouped_values.each do |key, value|
+ grouped_values[key] = value.count
end
end

0 comments on commit 87d156a

Please sign in to comment.