Created
February 18, 2011 02:03
-
-
Save jamie/833125 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
| require 'rubygems' | |
| require 'isolate' | |
| Isolate.now! do | |
| gem 'sinatra' | |
| end | |
| require 'sinatra' | |
| $x = 0 | |
| $procs = {} | |
| helpers do | |
| def magic_link_to(name, &behaviour) | |
| $procs[caller.first] = behaviour | |
| '<a href="/proc?q=%s">%s</a>' % [URI.escape(caller.first), name] | |
| end | |
| end | |
| get '/' do | |
| erb :default | |
| end | |
| get '/proc' do | |
| $procs[params['q']].call | |
| redirect '/' | |
| end | |
| __END__ | |
| @@ layout | |
| <!doctype html> | |
| <html> | |
| <body> | |
| <%= yield %> | |
| </body> | |
| </html> | |
| @@ default | |
| <p>Hello. $x is <%= $x %>.</p> | |
| <p><%= magic_link_to('decrement') { $x -= 1 } %> or | |
| <%= magic_link_to('increment') { $x += 1 } %>.</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment