Ruby cheat sheet
A scannable Ruby reference: 7 short snippets across 5 topics, each linking back to the lesson it came from.
At a glance
| Topic | What it covers | |
|---|---|---|
| Standard library and a short note on Rails | Rails is a full framework built on Ruby: convention over configuration, MVC, and generators that write the boilerplate | lesson |
| Gems, Bundler and project layout | Use require_relative for files inside your own project and require for gems. Mixing them up makes a library work from | lesson |
| Testing with Minitest and RSpec | Minitest assertions, RSpec describe and it blocks, let and subject, doubles and mocks, and organising a suite that | lesson |
| Background jobs and the Ruby web stack | Jobs are arguments, not state. Pass identifiers and re-load records inside perform; serialising a large object graph | lesson |
| Deployment, performance and next steps | Bundler in production, Puma tuning, memory and GC behaviour, profiling with StackProf, structured logging, and where to | lesson |
Quick snippets
Standard library and a short note on Rails
A short note on Rails
gem install rails
rails new blog
cd blog
bin/rails server
bin/rails generate model Post title:string body:text published_at:datetime
bin/rails generate controller Posts index show
bin/rails db:migrateFull lesson: Standard library and a short note on Rails →
Gems, Bundler and project layout
Gemfile and the lockfile
bundle install # resolves and writes Gemfile.lock
bundle update rack # move one gem within its constraint
bundle exec rspec # run against locked versions
bundle outdated
bundle lock --add-platform x86_64-linux arm64-darwinFull lesson: Gems, Bundler and project layout →
Testing with Minitest and RSpec
Doubles, mocks and stubs
# controlling time without a dependency
travel_to(Time.utc(2026, 6, 1)) do
expect(subscription.renews_on).to eq(Date.new(2026, 7, 1))
end
# freezing randomness so a failure is reproducible
srand(1234)
expect(generator.pick).to eq("gamma")
Keeping the suite useful
bundle exec rspec --format progress --profile 10
bundle exec rspec spec/models/book_spec.rb:42 # run one example
bundle exec rake test # minitest through Rake
COVERAGE=1 bundle exec rspec # with simplecov enabledFull lesson: Testing with Minitest and RSpec →
Background jobs and the Ruby web stack
Running the queue in production
bundle exec sidekiq -C config/sidekiq.yml -e production
# config/sidekiq.yml
# :concurrency: 10
# :queues:
# - [critical, 4]
# - [default, 2]
# - [mail, 1]
# :max_retries: 5Full lesson: Background jobs and the Ruby web stack →
Deployment, performance and next steps
Deploying Ruby
# deterministic install without touching the system gem path
bundle config set --local deployment true
bundle config set --local without "development test"
bundle config set --local path vendor/bundle
bundle install --jobs 4 --retry 3
# run behind a process manager
bundle exec puma -C config/puma.rb
# health check for the load balancer
curl -fsS http://127.0.0.1:3000/health || exit 1
Measuring before tuning
# structured logs a platform can index
require "json"
require "logger"
logger = Logger.new($stdout).tap { |l| l.formatter = proc do |severity, time, _prog, msg|
JSON.generate(level: severity.downcase, ts: time.utc.iso8601(3), msg: msg) + "\n"
end }
logger.info("report built rows=#{rows} ms=#{elapsed_ms}")
# never log tokens, passwords, card data or full request bodiesFull lesson: Deployment, performance and next steps →
FAQ
Is this Ruby cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 5 lessons of the Ruby course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Ruby course — it carries the worked explanations, the edge cases and the exercises behind every line here.
Related cheat sheets
Last refreshed 2026-09-27.