Ruby quick reference

Runs in Zerethon IDE · Ruby 4.0 Official Ruby documentation ↗

Ruby 4.0 essentials: values and types, control flow, methods and blocks, arrays and hashes, classes and modules, strings, input and files — and how a Ruby program runs in Zerethon IDE.

Written for Ruby 4.0. Examples that show an output were run in the Zerethon sandbox (Ruby 4.0) on 2026-10-24.

Basics

  • Hello, World

    The smallest Ruby program, and the difference between puts, print and p.

  • Variables and types

    Numbers, strings, symbols, true / false, nil, and converting with to_i, to_f, to_s and Integer().

  • Conditions and loops

    if / elsif / unless, case, iterating with each and times, while, and next / break.

  • Methods and blocks

    Define methods with def, keyword arguments, implicit return, blocks with yield, and lambdas.

Data

  • Arrays and hashes

    Arrays and hashes, map / select / sort_by, fetch with a default, and other everyday Enumerable methods.

  • Classes and modules

    Define classes with initialize and attr_reader, inherit with <, mix in modules, and use Struct.

  • Strings

    Interpolation, common string methods, format, and regular expressions with scan, =~ and [].

Input and files

In Zerethon IDE

  • Running Ruby in Zerethon IDE

    What Run does with your project, the time limit, input, tests, and what a run cannot do.

  • Common errors

    What NoMethodError on nil, NameError, ArgumentError, TypeError, ZeroDivisionError and SyntaxError mean and how to fix them.

  • Official documentation

    Where to read more: the Ruby documentation site, the quick start, and the core and standard library reference.

References