Skip to content

Instantly share code, notes, and snippets.

@retro
Created August 30, 2012 10:18
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 retro/3525609 to your computer and use it in GitHub Desktop.
Save retro/3525609 to your computer and use it in GitHub Desktop.
Map classes to sinatra routes
require 'rubygems'
require 'sinatra'
class Handler
attr_reader :context
def initialize(context)
@context = context
end
def render
unless context.params[:username].nil?
"Hello #{context.params[:username]}"
else
"Hello guest"
end
end
end
def Handler
klass = Handler
Proc.new do
klass.new(self).render
end
end
get "/", &Handler()
get "/:username", &Handler()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment