Skip to content

Instantly share code, notes, and snippets.

@crm114
Created July 21, 2012 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crm114/3156919 to your computer and use it in GitHub Desktop.
Save crm114/3156919 to your computer and use it in GitHub Desktop.
Sinatra: Send method test
require 'sinatra'
class Car
def mpg
return "50 MPG"
end
def length
return "2.5 meters"
end
def width
return "1 meter"
end
end
get '/' do
"Check the mpg, length or width of a car."
end
get '/:method' do
car = Car.new
begin
info = car.send(params[:method])
"#{info}"
rescue
"Not a valid car parameter"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment