Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented May 13, 2011

Totally awesome! Thank you for this.

@jfeaver

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.