Created
August 30, 2012 10:18
-
-
Save retro/3525609 to your computer and use it in GitHub Desktop.
Map classes to sinatra routes
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 '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