coderef

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.

  • Print
  • Variables
  • Read input
  • Convert
  • Nil-safe call
  • Default value

Strings

Text.

  • Interpolation
  • Common methods
  • Contains / starts with
  • Replace
  • Split / join
  • Format

Arrays

Ordered lists.

  • Create / add
  • Access
  • Transform
  • Aggregate
  • Sort
  • Find / check
  • Unique / flatten
  • Reverse
  • With index
  • Group / count

Hashes

Key–value maps.

  • Create
  • Get / set
  • Loop
  • Transform
  • Merge / keys

Control flow & methods

Logic and reuse.

  • If / unless
  • Case
  • Loops
  • Method
  • Keyword arguments
  • Block / yield
  • Lambda

Classes, errors & gems

Objects and tooling.

  • Class
  • Inheritance / module
  • Struct / Data
  • Rescue errors
  • Raise
  • Files
  • Gems

← All quick references