Commit 56ca7ac

mo khan <mo@mokhan.ca>
2014-04-26 19:52:24
push up calculate method to base class.
1 parent dc67d5c
Changed files (4)
lib/mathy/operations/addition.rb
@@ -4,12 +4,6 @@ module Mathy
       def initialize(difficulty)
         super(difficulty, "+")
       end
-
-      def calculate(operands)
-        operands.inject do |result, x|
-          result + x
-        end
-      end
     end
   end
 end
lib/mathy/operations/operation.rb
@@ -17,6 +17,10 @@ module Mathy
       def matches?(other_key)
         key == other_key
       end
+
+      def calculate(operands)
+        operands.inject { |result, x| result.send(key.to_sym, x) }
+      end
     end
   end
 end
lib/mathy/operations/subtraction.rb
@@ -4,12 +4,6 @@ module Mathy
       def initialize(difficulty)
         super(difficulty, "-")
       end
-
-      def calculate(operands)
-        operands.inject do |result, x|
-          result - x
-        end
-      end
     end
   end
 end
lib/mathy/game.rb
@@ -6,7 +6,8 @@ module Mathy
     end
 
     def play(console)
-      console.display_results(@player, @score, play_turns(console))
+      turns_played = play_turns(console)
+      console.display_results(@player, @score, turns_played)
     end
 
     private