Permalink
Browse files

Address the #bob comment

  • Loading branch information...
camillebaldock committed Sep 3, 2014
1 parent 1376b91 commit 97921d09ea92826ee00f20615a6787614ccbf442
Showing with 17 additions and 14 deletions.
  1. +4 −0 README.md
  2. +9 −10 lib/hand.rb
  3. +4 −4 spec/hand_spec.rb
View
@@ -15,3 +15,7 @@ in a "shameless green" style
2) Address the ```##DUPE! pip_count``` comment
the ```pip_count``` and ```suit_count``` methods are essentially duplicates of each other
+
+3) Address the ```##bob``` comment
+##bob is a slightly silly notation I use when I have a method/class/variable with a name that does not please me (not descriptive enough, actually wrong, any possibility for confusion) but I can't think of a better name at time of writing
+In this case ```pip_count``` and ```suit_count``` don't describe the intention of those methods
View
@@ -38,40 +38,39 @@ def rank
end
end
- ##bob
- def pip_count
- value_occurence_count(cards.map(&:pips))
+ def pips_occurence_count
+ value_occurence_count(cards.map(&:pips)).values
end
- def suit_count
- value_occurence_count(cards.map(&:suit))
+ def suit_occurence_count
+ value_occurence_count(cards.map(&:suit)).values
end
private
def has_four
- pip_count.values.include?(4)
+ pips_occurence_count.include?(4)
end
def has_three
- pip_count.values.include?(3)
+ pips_occurence_count.include?(3)
end
def has_two_pairs
- grouped_pip_counts = pip_count.values.group_by { |i| i }
+ grouped_pip_counts = pips_occurence_count.group_by { |i| i }
grouped_pip_counts[2] && grouped_pip_counts[2].size == 2
end
def has_two
- pip_count.values.include?(2)
+ pips_occurence_count.include?(2)
end
def full_house
has_three && has_two
end
def flush
- suit_count.values.include?(5)
+ suit_occurence_count.include?(5)
end
def straight
View
@@ -45,15 +45,15 @@
end
end
- describe "#pip_count" do
+ describe "#pips_occurence_count" do
it "returns information about the winning potential of the hand" do
- expect(pair_hand.pip_count).to eq ({ 5 => 2, 6 => 1, 7 => 1, 8 => 1 })
+ expect(pair_hand.pips_occurence_count).to eq ({ 5 => 2, 6 => 1, 7 => 1, 8 => 1 }.values)
end
end
- describe "#suit_count" do
+ describe "#suit_occurence_count" do
it "returns information about the winning potential of the hand" do
- expect(pair_hand.suit_count).to eq ({ :heart => 1, :diamonds => 4 })
+ expect(pair_hand.suit_occurence_count).to eq ({ :heart => 1, :diamonds => 4 }.values)
end
end

0 comments on commit 97921d0

Please sign in to comment.