Ruby Quick Reference
Ruby essentials: variables, strings, arrays, hashes, blocks, control flow, classes, modules and gems.
6 sections · 41 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Variables and output.
TaskCode
- Variables
- Read input
- Convert
- Nil-safe call
- Default value
Strings
Text.
TaskCode
- Interpolation
- Common methods
- Contains / starts with
- Replace
- Split / join
- Format
Arrays
Ordered lists.
TaskCode
- Create / add
- Access
- Transform
- Aggregate
- Sort
- Find / check
- Unique / flatten
- Reverse
- With index
- Group / count
Hashes
Key–value maps.
TaskCode
- Create
- Get / set
- Loop
- Transform
- Merge / keys
Control flow & methods
Logic and reuse.
TaskCode
- If / unless
- Case
- Loops
- Method
- Keyword arguments
- Block / yield
- Lambda
Classes, errors & gems
Objects and tooling.
TaskCode
- Class
- Inheritance / module
- Struct / Data
- Rescue errors
- Raise
- Files
- Gems