Skip to content

Commit

Permalink
Creating OPERATORS hash in CalculatorOperations module and removing t…
Browse files Browse the repository at this point in the history
…he hardcoded value in calculations.rb
  • Loading branch information
bishboria committed Sep 10, 2011
1 parent 0fb77c6 commit 3f8d971
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
@@ -1,14 +1,16 @@
require 'calculator_operations'

module Calculations

def follow_the_steps_for sum
enter_numbers_and_operators_for sum
end

def enter_numbers_and_operators_for sum
operator = {"+" => :plus, "-" => :minus, "=" => :equals}
operators = CalculatorOperations::OPERATORS
sum.each do | token |
enter token.to_i if token =~ /\d+/
press operator[token] if operator.include? token
press operators[token] if operators.include? token
end
end
end
Expand Down
1 change: 1 addition & 0 deletions Examples/Calculator/lib/calculator_operations.rb
@@ -1,3 +1,4 @@
module CalculatorOperations
OPERATORS = { '+' => :plus, '-' => :minus, '=' => :equals }
OPERATIONS = { 'plus' => :+, 'minus' => :-, 'equals' => '=' }
end

0 comments on commit 3f8d971

Please sign in to comment.