Skip to content
Tutorials Center
My learning

Topics

Lesson 117 of 134 ยท Web and Ecosystem

The Ruby Ecosystem

A guided tour of the Ruby ecosystem - Rails and Hanami, Sidekiq-style background jobs, Jekyll-style site generators, Chef-style automation, testing tools, and what Ruby work looks like today.

A language is more than its syntax. When you choose Ruby, you also choose a community, a package index with hundreds of thousands of gems, and a set of well-known tools that shaped how the industry builds software. This lesson is a map of that territory. For each major project you will learn what it is for, which Ruby ideas it is built from, and how to recognise those ideas in your own code.

None of the big projects can be installed on our runner, since there is no network and no gems beyond those that ship with Ruby. So every real-world snippet here is labelled read-only. To keep the tour hands-on, we build small plain-Ruby stand-ins that capture the central idea of each tool: a job queue, a static site generator, a configuration-management DSL. Building the idea once is the best way to understand the tool for good.

The ecosystem in numbers

Ruby has a central repository, rubygems.org, where gems are published, and a command (gem) plus a project tool (Bundler) to install them (RubyGems and Bundler). Part of the standard library ships as default gems (json, set, optparse, erb, ...) which are installed with Ruby and can be upgraded separately. A few older libraries are bundled gems: installed with Ruby but not loaded by default inside Bundler projects, so a real project must list them in the Gemfile. We can inspect that distinction on the runner.

Ruby Default gems and bundled gems on this Ruby

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

The result shows that json is a default gem, while csv is installed but not a default gem, which marks it as a bundled gem: a plain script can still require 'csv', but a Bundler project must add gem "csv" first. Rails and Sidekiq are not installed, so requiring them raises LoadError. In your own projects, running bundle add sidekiq and bundle install is the fix.

Web frameworks

Ruby on Rails is the framework that made Ruby famous, and the reason many people first learn the language. It bundles routing, controllers, views, an ORM (ActiveRecord), background jobs (Active Job), mailers, file uploads, WebSockets and a testing setup into one coherent whole built on "convention over configuration". Large products such as GitHub, Shopify, GitLab and Basecamp are or were built on it. Read the Rails overview for the structure of an app.

Sinatra and Roda are small routing libraries for services where Rails would be too much, and Hanami is a newer full-stack framework that favours explicit, separate objects over Rails' global conventions. They all sit on Rack (Sinatra and Rack), which is why a middleware written for one often works in the others.

A very rough guide:

  • Building a product with a database, accounts, e-mail and a team? Rails, because the conventions are an accelerator.
  • A small API, webhook receiver or internal tool? Sinatra or Roda.
  • Large domain with strict boundaries, and you do not mind more ceremony? Hanami.

Background jobs: the Sidekiq idea

Web requests must answer fast. Anything slow (sending e-mail, resizing an image, calling a payment API) is moved out of the request into a background job. The most popular Ruby tool for this is Sidekiq: it stores jobs in Redis, and a separate set of worker threads takes jobs out and runs them. The code you write is a class with a perform method:

Ruby
# read-only example: needs the sidekiq gem and a Redis server
class WelcomeEmailJob
  include Sidekiq::Job

  def perform(user_id)
    user = User.find(user_id)
    Mailer.welcome(user).deliver_now
  end
end

WelcomeEmailJob.perform_async(42)   # returns immediately; a worker runs it later

Notice that the job receives an id, not a whole object. Jobs are stored as JSON, so arguments must be simple values: strings, numbers, arrays, hashes. Look the record up again when the job runs, so you work with fresh data.

The core of such a system is a queue plus workers, and Ruby's standard library has both (Mutex, Queue and ConditionVariable, Thread pools). Here is a stand-in with the same shape: perform_async, JSON-safe arguments, retries, and a failed-jobs list.

Ruby A Sidekiq-style job runner

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

Real Sidekiq adds a lot on top: persistence in Redis (jobs survive a crash), scheduling, a web dashboard, exponential back-off between retries, uniqueness and rate limiting. But the shape is the one you just built. Two lessons carry over. Jobs must be idempotent, because retries mean a job may run more than once. And arguments must survive a trip through JSON, so symbols become strings and objects disappear.

Static sites and documentation: the Jekyll idea

Jekyll, the engine behind GitHub Pages, turns a folder of text files into a website. Each page has a small block of YAML at the top, called front matter, followed by content; a template wraps the content; the result is plain HTML files. It is written in Ruby and uses the very libraries you already met: yaml, erb-like templating (Liquid), and file handling. A page looks like this (read-only):

TEXT
---
title: Hello
layout: post
tags: [ruby, blog]
---
Welcome to **my** site.

The two stages (split front matter from the body, then render into a layout) fit in a short script. The stand-in below uses YAML from the standard library and ERB (ERB Templates).

Ruby A tiny static site generator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

The output shows two finished HTML pages, then a clear build error for a file with no front matter. Real Jekyll adds Markdown conversion (kramdown), collections, includes and plugins, but still follows this loop: read files, extract metadata, render, write. Other Ruby documentation and static-site tools include Middleman, Bridgetown and YARD, the standard way to document Ruby libraries.

Automation, DevOps and everyday tools

Ruby is popular for tooling because it reads like a configuration file and yet is a full language:

  • Homebrew, the package manager of macOS, is written in Ruby and its formulas are Ruby classes.
  • Chef and Puppet describe the desired state of servers with a Ruby DSL. Vagrant (virtual machines) uses a Ruby Vagrantfile.
  • CocoaPods and Fastlane automate iOS and Android builds.
  • Capistrano deploys applications over SSH, and Rake runs project tasks (Rake and Automation).
  • Metasploit, a security-testing framework, is largely Ruby.

What these have in common is the DSL style plus one deep idea: declare the desired state and let the tool make it true. Running it twice does nothing the second time. Here is a miniature in the spirit of Chef: resources describe what should exist, a converge step compares with the current world and only acts on differences.

Ruby A Chef-style desired-state DSL

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

The first run changes everything, the second run changes nothing (this property is called idempotence), and the third changes only the file whose content differs. The DSL works because converge runs the block with instance_eval, so package and file become the machine's own methods (instance_eval and class_eval).

Testing and quality tools

The Ruby community takes testing seriously. Minitest ships with Ruby (Testing with Minitest); RSpec is the popular alternative with a behaviour-style syntax (RSpec Overview). RuboCop checks style and finds suspicious code (Style and Linting), SimpleCov measures test coverage, Brakeman scans Rails apps for security problems, and bundler-audit warns about gems with known vulnerabilities. A typical project runs all of them in continuous integration.

Other corners of the ecosystem

  • Hotwire (Turbo and Stimulus) and ViewComponent build interactive Rails pages without a JavaScript front-end framework.
  • Sequel, ROM and ActiveRecord access databases (Database Access Ideas).
  • Nokogiri parses HTML and XML; Faraday and HTTParty call web APIs; Puma is the most common application server.
  • Sorbet and RBS with Steep add optional type checking. Ruby ships with RBS for its core classes.
  • JRuby (Ruby on the Java virtual machine) and TruffleRuby (Ruby on GraalVM) are alternative implementations for projects that need Java libraries or more raw speed. mruby is a tiny embeddable Ruby.
  • Ruby 4.0 itself keeps evolving, with a new parser (Prism), two JIT compilers (YJIT and ZJIT) and the experimental Ractors (Ruby Versions and Changes).

Working with Ruby: honest notes

Ruby is a mature language, not a fashionable one, and that has consequences worth knowing. Most Ruby jobs involve Rails applications, often large and long-lived: products maintained for ten years or more. That means a lot of work is reading, extending and improving existing code, so skills that matter beyond the language are tests, refactoring, SQL and database design, performance debugging, and understanding how a request flows through a web stack. Companies range from start-ups that value shipping speed to big businesses with huge Rails monoliths.

Job markets differ widely between countries and change over time, so check current listings in the regions you care about instead of trusting any article's numbers. Whatever the market does, Ruby's ideas travel well: blocks, expressive DSLs, strong conventions and a love of readable code have influenced languages from Python to Swift to Elixir.

A practical path from here:

  1. Finish the core language track and the projects section.
  2. Learn Git and SQL (Git, SQL), the two tools every Ruby job assumes.
  3. Build a small Rails app with a database, a login, and a few tests, and put it online.
  4. Read the source of a gem you use. Gems are ordinary Ruby, and reading them is the quickest way to learn.
  5. Contribute a fix or documentation improvement to an open-source project.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the difference between a default gem and a bundled gem?

    Both ship with Ruby, but a bundled gem such as csv is not on the load path inside a Bundler project unless your Gemfile names it.
  2. 2. Why does a background job usually receive a user id instead of the User object?

    The queue serializes arguments to JSON. Passing an id and looking the record up inside the job also avoids working with stale data.
  3. 3. What does idempotent mean for a configuration or job runner?

    Idempotence means that repeating the operation leaves the system in the same state, which makes retries and repeated deployments safe.
  4. 4. Which tool is written in Ruby and used by macOS developers to install software?

    Homebrew is a Ruby program, and its formulas are Ruby classes.
  5. 5. What happens when you require 'sidekiq' on a machine where the gem is not installed?

    Ruby never installs gems on its own. A missing library raises LoadError, and the fix is to add the gem to the Gemfile and run bundle install.

Summary

  • The ecosystem is built on rubygems.org, RubyGems and Bundler; some standard libraries are default gems, others (csv, base64, ostruct, ...) are bundled gems that a real project must list.
  • Rails is the dominant full-stack framework; Sinatra, Roda and Hanami offer smaller or differently structured alternatives, all on top of Rack.
  • Background-job tools such as Sidekiq are queues plus workers, with JSON-safe arguments, retries and idempotent jobs.
  • Jekyll-style generators read front matter, render templates and write files; Chef-style tools declare desired state and converge to it.
  • Minitest, RSpec, RuboCop and friends make testing and style part of daily work.
  • Most Ruby work involves maintaining Rails applications, so tests, SQL, Git and reading other people's code are as valuable as the language itself.

Next: Project: Expression Calculator