Skip to content

Instantly share code, notes, and snippets.

@rkh
Created May 13, 2011 07:02
Show Gist options
  • Save rkh/970108 to your computer and use it in GitHub Desktop.
Save rkh/970108 to your computer and use it in GitHub Desktop.
require 'sinatra/base'
class MyApp < Sinatra::Base
@@my_app = {}
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
class FooController < MyApp
map '/foo'
get '/' do
"foo"
end
end
class BarController < MyApp
map '/bar'
get '/' do
"bar"
end
end
run! if __FILE__ == $0
end
@ariejan
Copy link

ariejan commented May 13, 2011

Totally awesome! Thank you for this.

@jfeaver
Copy link

jfeaver commented Nov 30, 2012

I built a more fleshed out application and used this code for controllers. I'm sharing a skeleton of it here: https://github.com/jfeaver/modular-sinatra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment