Created
July 21, 2012 19:35
-
-
Save crm114/3156919 to your computer and use it in GitHub Desktop.
Sinatra: Send method test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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