Skip to Content
Sinatra: Up and Running
book

Sinatra: Up and Running

by Alan Harris, Konstantin Haase
November 2011
Intermediate to advanced
122 pages
2h 23m
English
O'Reilly Media, Inc.
Content preview from Sinatra: Up and Running

Chapter 4. Modular Applications

In Chapter 3, we saw that normal Sinatra applications actually live in Sinatra::Application, which is a subclass of Sinatra::Base. Apparently, if we don’t use the Top Level DSL, it is possible to just require 'sinatra/base'. And it shouldn’t be surprising by now that it is common practice to actually do so. If we do, we usually don’t use Sinatra::Application, but instead we create our own subclass of Sinatra::Base.

This style is called a modular application, as opposed to classic applications that are using the Top Level DSL. While classic applications assume a certain style by default and extend Object, starting with a modular application assumes next to nothing about your application setup.

Caution

For some reason, it is a common misconception that modular applications are superior to classic applications, and that really advanced users only use modular style. From time to time it has even been proposed to drop classic style all together. This is utter nonsense and no one on the Sinatra core team shares this view. Sinatra is all about simplicity and if you can use a classic application, you should.

But why would one want to use modular style? If you activate the Top Level DSL (by requiring sinatra), Sinatra extends the Object class, somewhat polluting the global namespace. This is not as bad as it sounds, since all delegation methods are marked private, just like Ruby’s built-in global methods, like puts. But still, especially if you ship your Sinatra ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Jump Start Sinatra

Jump Start Sinatra

Darren Jones
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao
Ruby in a Nutshell

Ruby in a Nutshell

Yukihiro Matsumoto
Refactoring in Ruby

Refactoring in Ruby

William C. Wake, Kevin Rutherford

Publisher Resources

ISBN: 9781449306847Errata Page