Ruby Cheat Sheet
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
A single-page, colour-coded summary of the Ruby language and its toolchain, written against Ruby 4.0 (Ruby 4.0.7; checked 2026-10-18) — the tool map (ruby, irb, ri, gem, bundle, rake, rdbg, rbs, rubocop) and useful ruby flags, a Gemfile and gemspec skeleton, magic comments, naming conventions and require, literals, variables and assignment forms, operator and precedence highlights, control expressions, method parameter order and argument forwarding, blocks, procs and lambdas, exceptions, the object model with an ancestors sketch, one-liners for the core types, Enumerable and lazy enumerators, pattern matching, metaprogramming, threads, fibers and Ractors, standard-library one-liners, Minitest, RSpec, RBS and RuboCop, YJIT and benchmarking, and a strip of what changed since older tutorials — handy for quick memorization or as a downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — Ruby Reference.
Getting started — Getting Started, Versions, Releases and Compatibility, Program Structure and Lexical Elements and Design Philosophy and Coming from Other Languages.
Core language — Literals, Variables, Constants and Scope, Assignment and Multiple Assignment, Operators and Precedence, Control Expressions, Methods and Parameters, Calling Methods and Argument Forwarding, Blocks, Procs and Lambdas and Exceptions and Error Handling.
Object model — Classes and Objects, Modules and Mixins, Singleton Classes and Class-Level Behavior, Method Lookup and super, Visibility and Encapsulation, Refinements and Monkey Patching, Conversions and Coercion, Equality, Hashing and Comparison and Object Lifecycle, Freezing and Copying.
Core types — Numbers, Strings, Encodings and Unicode, Symbols, Arrays, Hashes, Ranges, Struct, Data and Value Objects, Sets, Time and Dates and Regular Expressions.
Iteration and pattern matching — Enumerable, Enumerators and Lazy Evaluation and Pattern Matching.
Metaprogramming and reflection — Dynamic Dispatch and Method Definition, Hooks, eval and DSLs and Reflection, Introspection and Tracing.
Concurrency — Threads and the GVL, Fibers and the Fiber Scheduler and Ractors.
Packaging and tooling — Code Loading: require and autoload, RubyGems and Bundler, Creating and Publishing Gems, and Rake, Ruby Command Line and Environment, IRB and Debugging, Documentation with RDoc and YARD and Command-Line Programs.
Standard library — IO, Files and Directories, Processes, Signals and Shell, Networking and HTTP, Serialization: JSON, YAML, CSV and Marshal, Standard Library Tour and Security.
Quality — Testing with Minitest, RSpec and Test Doubles, Type Checking with RBS, TypeProf, Steep and Sorbet and Style, Linting and Static Analysis.
Design and practice — Idioms, Style and Clean Code, SOLID and Design Patterns, Application Architecture in Plain Ruby and Common Mistakes and Gotchas.
Performance and internals — Performance, Benchmarking and Profiling, YJIT, ZJIT and the VM and Garbage Collection and Memory.
Interop — C Extensions, FFI and WebAssembly.
Practice and evolution — What’s New and Migrating Older Code.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.