In today’s post, we’ll cover Ruby frameworks. There is one I’m pretty sure you’ve heard about, and its name is Ruby on Rails. If you walk up to a random software developer and ask them to name a Ruby framework, it’s very likely that Ruby on Rails will be their answer and that would hardly be surprising.
I think it’s fair to say that Ruby on Rails changed the landscape of web development. This highly successful framework managed to put some best practices and conventions on a lot of developers’ radar, and it also helped to bring some revolutionary services to life, especially the usage of Model-View-Controller (MVC). Last but not least, it’s responsible for skyrocketing the popularity of the Ruby programming language to a whole new level. For that reason, Stackify has started supporting Ruby on Rails monitoring as well. If you’re using Ruby on Rails, it’s worth checking out Retrace.
That’s not to say that Ruby itself isn’t awesome. It is. And as proof of said awesomeness is the sheer number of Ruby frameworks out there. There are full-blown, monolithic ones and tiny, minimalistic ones. You can have frameworks that stand on their own; others, you must use as a complement to other tools.
The Ruby ecosystem has plenty of options to cover the needs and preferences of all developers, as you’ll see in this post.
I know you could’ve seen this coming miles away, but it’s impossible to talk about Ruby frameworks without mentioning the most famous among them. So, Rails it is.
Ruby on Rails, sometimes called just “Rails,” is an open-source web development framework. David Heinemeier Hansson, a.k.a. DHH, released the first version of Rails as an open-source project back in 2005, after using it to build what would become the Basecamp project management system.
Besides using the popular model-view-controller (MVC) pattern, Rails is based upon some well-known software development guidelines and philosophies. Probably chief among them is “convention over configuration.” That means that, unlike many popular frameworks, Rails doesn’t generally require the user to create a lot of mappings and configurations. Instead, the framework itself makes many assumptions based on some simple conventions.
The Rails framework enables developers to get a database-backed website up and running in way less time than it would’ve been possible by using its competitors. Due to its convention-based approach, the Rails framework saves developers from writing a lot of boilerplate code, freeing them to focus on the business part of the code.
Ruby on Rails has been successful in increasing the popularity of not only Ruby itself, but also the convention-based approach to web frameworks. Nowadays, there are database-backed, MVC-convention-based web frameworks available in a variety of languages and platforms that clearly took inspiration from the “Rails way.”
The second Ruby framework on our list is Hanami. Released initially as Lotus by Luca Guidi, the framework was renamed to Hanami in 2016, due to trademark issues.
The framework’s site describes it as a “modern web framework for Ruby”, and claims it’s optimized for performance. Hanami makes use of CDNs (content delivery networks) to deliver responses as fast as possible, and it consumes 60% less memory than other Ruby frameworks.
Hanami is heavily influenced by Robert “Uncle Bob” Martin’s clean architecture. Its architectural style assumes your project can contain n apps. The same Ruby process runs all apps in your project, and they all reside in the same codebase. The most popular type of application is the web app, so Hanami automatically generates that one for you. You could have different apps for what Martin calls “delivery mechanisms.” In clean architecture lingo, a delivery mechanism is just a way of delivering functionalities to the final user.
Similar to Rails (and several other Ruby frameworks), Hanami follows the MVC pattern. Unlike Rails, though, it splits the functionality of the Model class into two parts. One is an entity class that models the behavior you need to express. The other is a repository class that handles the persistence for the entity.
Sinatra is a web application framework, first released in 2007. According to its site, Sinatra is a “DSL for quickly creating web applications in Ruby with minimal effort.” As you’ve probably guessed, the creators named the framework after singer Frank Sinatra.
Sinatra aims to be small and flexible. It doesn’t follow the typical MVC patterns used in other Ruby frameworks (and web frameworks in general, not only Ruby ones). Instead, it provides the developer a DSL with which they can define routes.
A route in Sinatra is a pair composed of an HTTP method and a pattern. The pattern is used to match URLs to blocks.
The next Ruby framework on our list is Cuba. According to the description on its GitHub repository, Cuba is “a microframework for web development originally inspired by Rum, a tiny but powerful mapper for Rack applications.”
The next Ruby framework on our list is Nancy. Nancy is a web development microframework that took inspiration from other frameworks such as Cuba and Sinatra. Sinatra’s influence on Nancy goes all the way to the naming of the framework: Nancy is Frank Sinatra’s daughter.
According to its GitHub repo, some of Nancy’s main features include its high speed, support for “Sinatra-like” routes, the possibility of halting execution at any point by employing Ruby’s native throw/catch mechanism, and last but not least, thread-safety.
The next item on our list is Grape, which is yet another Ruby framework that falls into the category of microframeworks. Grape is one of the newest Ruby frameworks out there. Its website describes it as an “opinionated framework for creating REST-like APIs in Ruby.” That pretty much sums it up.
You can run Grape on Rack or use it as a complement to other frameworks.
After covering so many minimalist frameworks, it’s time to get back to a more full-fledged framework with Padrino. This framework uses Sinatra as its core. According to its site, Padrino “was created to make it fun and easy to code more advanced web applications while still adhering to the spirit that makes Sinatra great!”
So, while Padrino is a “full” framework, closer to Rails in essence than to Grape, Cuba, or other microframeworks, it also strives to be as small, fast, and lightweight as possible.
In today’s post, you’ve learned about some of the Ruby frameworks available out there. Some are very famous, while others are less so. Regardless, I think this drives its message home: there are many Ruby frameworks at your disposal. Ruby on Rails is without a doubt the most famous of them all. If it suits your needs, go for it. But if it doesn’t, you have plenty of options to choose from.
And, of course, frameworks aren’t all there is to software development. There are a plethora of useful Ruby tools out there, so you must keep your eyes open for opportunities to boost both your team’s productivity and the quality of its output. More specifically, we invite you to take a look at Stackify’s Retrace, which can make application monitoring and profiling in Ruby as easy as 1-2-3.