Created
September 22, 2011 08:14
-
-
Save nbqx/1234310 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require 'sinatra' | |
module MyCustomRequestMethod | |
def hey(path,opts={},&blk) | |
route __method__.to_s.upcase,path,opts,&blk | |
end | |
end | |
module Sinatra | |
register MyCustomRequestMethod | |
end | |
script = <<SCRT | |
def upcase(str) | |
str.upcase.split(//).reverse.join('') | |
end | |
SCRT | |
## ex. curl -X HEY "http://localhost:4567" -d "text=abcdefghijk" | |
hey '/' do | |
puts "request.env[\"REQUEST_METHOD\"] is `#{request.env["REQUEST_METHOD"]}`, params is "+params.inspect | |
eval(script).__send__ :upcase, params[:text] | |
end | |
get '/' do | |
script | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment