Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created September 22, 2011 08:14
Show Gist options
  • Save nbqx/1234310 to your computer and use it in GitHub Desktop.
Save nbqx/1234310 to your computer and use it in GitHub Desktop.
# -*- 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