Commit f9eafab

mo khan <mo@mokhan.ca>
2014-04-26 15:26:15
move x and y generation to each operation.
1 parent bb8ff89
Changed files (3)
lib/mathy/operations/addition.rb
@@ -8,8 +8,8 @@ module Mathy
         @key = "+"
       end
 
-      def play_turn(x: rand(10), y: rand(20), correct_answer: x + y)
-        @verifier.check_answer("#{x} + #{y} = ", correct_answer)
+      def play_turn(x: rand(10), y: rand(20))
+        @verifier.check_answer("#{x} + #{y} = ", x + y)
       end
 
       def matches?(other_key)
lib/mathy/operations/subtraction.rb
@@ -8,8 +8,8 @@ module Mathy
         @key = "-"
       end
 
-      def play_turn(x: rand(10), y: rand(20), correct_answer: x - y)
-        @verifier.check_answer("#{x} - #{y} = ", correct_answer)
+      def play_turn(x: rand(10), y: rand(20))
+        @verifier.check_answer("#{x} - #{y} = ", x - y)
       end
 
       def matches?(other_key)
lib/mathy/game.rb
@@ -7,7 +7,7 @@ module Mathy
 
     def play(games_to_play = 2, operation)
       games_to_play.times do
-        @score += 1 if operation.play_turn(x: rand(10), y: rand(20))
+        @score += 1 if operation.play_turn
       end
 
       display_results(@name, @score, games_to_play)