Skip to content

Instantly share code, notes, and snippets.

@jamie
Created February 18, 2011 02:03
Show Gist options
  • Select an option

  • Save jamie/833125 to your computer and use it in GitHub Desktop.

Select an option

Save jamie/833125 to your computer and use it in GitHub Desktop.
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