Skip to content

Instantly share code, notes, and snippets.

@ColinTheRobot
Created March 19, 2014 14:21
Show Gist options
  • Save ColinTheRobot/9642615 to your computer and use it in GitHub Desktop.
Save ColinTheRobot/9642615 to your computer and use it in GitHub Desktop.
sinatra_calc(not working still)
require 'sinatra'
require 'sinatra/reloader' if development?
require 'pry'
get "/" do
"Welcome to this wicked CAL-cu-LAY-torrrr....\n\n"
end
# def shove_it(shove_it)
# @array = Array.new
# @array.push(shove_it)
# end
array = []
def show_it
array.map { |calculation| puts calculation }
end
get "/calculator" do
show_it
end
get "/calculator/3" do
#should show the third calculations
end
post "/calculator/add" do
binding.pry
calculation = params[:first].to_f + params[:second].to_f
array << "#{params[:first]} + #{params[:second]} = #{calculation}"
binding.pry
"#{params[:first]} + #{params[:second]} = #{calculation}\n\n"
binding.pry
end
post "/calculator/subtract" do
calculation = params[:first].to_f - params[:second].to_f
"#{params[:first]} - #{params[:second]} = #{calculation}\n\n"
end
post "/calculator/multiply" do
calculation = params[:first].to_f * params[:second].to_f
"#{params[:first]} * #{params[:second]} = #{calculation}\n\n"
end
post "/calculator/divide" do
calculation = params[:first].to_f / params[:second].to_f
"#{params[:first]} / #{params[:second]} = #{calculation}\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment