Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7a42de0e45
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (32 sloc) 1.348 kb
<p><tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar
for your extensions. It allows you to call directly inside your extension
module almost any <tt>Sinatra::Base</tt> method. This means you can use
<tt>get</tt> to define a route, <tt>before</tt> to define a before filter,
<tt>set</tt> to define a setting, a so on.</p>
<p>Is important to be aware that this mixin remembers the methods calls you
make, and then, when your extension is registered, replays them on the
Sinatra application that has been extended. In order to do that, it
defines a <tt>registered</tt> method, so, if your extension defines one
too, remember to call <tt>super</tt>.</p>
<p>Just require the mixin and extend your extension with it:</p>
<pre>require 'sinatra/extension'
module MyExtension
extend Sinatra::Extension
# set some settings for development
configure :development do
set :reload_stuff, true
# define a route
get '/' do
'Hello World'
# The rest of your extension code goes here...
<p>You can also create an extension with the <tt>new</tt> method:</p>
<pre>MyExtension = do
# Your extension code goes here...
<p>This is useful when you just want to pass a block to
Jump to Line
Something went wrong with that request. Please try again.