Commit cec9306

mo khan <mo@mokhan.ca>
2014-04-26 21:57:28
replace addition and subtraction classes in place of operator.
1 parent 56ca7ac
Changed files (5)
lib/mathy/difficulties/grade_two.rb
@@ -6,9 +6,10 @@ module Mathy
       end
 
       def choose_operation(console)
+        verifier = Verification.new(console)
         console.operation?([
-          Operations::Addition.new(self),
-          Operations::Subtraction.new(self)
+          Operations::Operation.new(self, "+", verifier),
+          Operations::Operation.new(self, "-", verifier)
         ])
       end
     end
lib/mathy/operations/addition.rb
@@ -1,9 +0,0 @@
-module Mathy
-  module Operations
-    class Addition < Operation
-      def initialize(difficulty)
-        super(difficulty, "+")
-      end
-    end
-  end
-end
lib/mathy/operations/subtraction.rb
@@ -1,9 +0,0 @@
-module Mathy
-  module Operations
-    class Subtraction < Operation
-      def initialize(difficulty)
-        super(difficulty, "-")
-      end
-    end
-  end
-end
lib/mathy/verification.rb
@@ -1,14 +1,18 @@
 module Mathy
   class Verification
+    def initialize(console)
+      @console = console
+    end
+
     def check_answer(question, correct_answer)
-      puts ""
-      print question
+      @console.report ""
+      @console.report question
       answer = gets
       if answer.to_i == correct_answer
-        print "Correct!"
+        @console.report "Correct!"
         return true
       end
-      print "The correct answer is #{correct_answer}."
+      @console.report "The correct answer is #{correct_answer}."
       false
     end
   end
lib/mathy.rb
@@ -4,9 +4,6 @@ require 'mathy/verification'
 require 'mathy/player'
 require 'mathy/game'
 require 'mathy/operations/operation'
-require 'mathy/operations/addition'
-require 'mathy/operations/subtraction'
-
 require 'mathy/difficulties/grade_two'
 
 module Mathy