diff options
| author | mo khan <mo@mokhan.ca> | 2014-04-26 13:52:24 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-04-26 13:52:24 -0600 |
| commit | 56ca7ac7ea6389045e2b0b71a829d38d588af7a8 (patch) | |
| tree | 47830ac79ed3d3af507e68b85191115d97030dcb | |
| parent | dc67d5cd588fdccc14e7682809eee7f00d070217 (diff) | |
push up calculate method to base class.
| -rw-r--r-- | lib/mathy/game.rb | 3 | ||||
| -rw-r--r-- | lib/mathy/operations/addition.rb | 6 | ||||
| -rw-r--r-- | lib/mathy/operations/operation.rb | 4 | ||||
| -rw-r--r-- | lib/mathy/operations/subtraction.rb | 6 |
4 files changed, 6 insertions, 13 deletions
diff --git a/lib/mathy/game.rb b/lib/mathy/game.rb index 2b4441e..a9f8b24 100644 --- a/lib/mathy/game.rb +++ b/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 diff --git a/lib/mathy/operations/addition.rb b/lib/mathy/operations/addition.rb index 615359c..a9c38ae 100644 --- a/lib/mathy/operations/addition.rb +++ b/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 diff --git a/lib/mathy/operations/operation.rb b/lib/mathy/operations/operation.rb index ed8774a..ba6a16d 100644 --- a/lib/mathy/operations/operation.rb +++ b/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 diff --git a/lib/mathy/operations/subtraction.rb b/lib/mathy/operations/subtraction.rb index 38b8ae6..72a7426 100644 --- a/lib/mathy/operations/subtraction.rb +++ b/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 |
