Permalink
Browse files

Initial refactoring to pull out operations.

  • Loading branch information...
1 parent 0d8f85b commit fe0022a2f9acee1990a265baed84a6d20037d87d @bishboria bishboria committed Sep 10, 2011
Showing with 9 additions and 5 deletions.
  1. +9 −5 Examples/Calculator/lib/web_calculator.rb
@@ -15,8 +15,12 @@ class WebCalculator < Sinatra::Base
end
helpers do
- def operate_with
- { 'plus' => :+, 'minus' => :-}
+ def available_operations
+ { 'plus' => :+, 'minus' => :- }
+ end
+
+ def operate_with operator
+ available_operations[operator]
end
def persist calc
@@ -25,7 +29,7 @@ def persist calc
def display_result_from calc
@display = calc.display
- @operations = operate_with
+ @operations = available_operations
erb :index
end
@@ -39,7 +43,7 @@ def selected_operator
def display_result_from_session
@display = session[:calc].display ||= 0
- @operations = operate_with
+ @operations = available_operations
erb :index
end
@@ -68,7 +72,7 @@ def load_calculator
if equals_pressed?
calculator.equals
else
- calculator.get_ready_to operate_with[selected_operator]
+ calculator.get_ready_to operate_with(selected_operator)
end
persist calculator
display_result_from calculator

0 comments on commit fe0022a

Please sign in to comment.