rubyguides

Reference

Keywords

Ruby keywords and special language constructs.

  1. Global Variables

    Global variables in Ruby use a $ prefix, stay visible across scopes, and should be reserved for rare program-wide state.

  2. Ruby keyword: case

    Ruby case expression: subject form vs no-subject form, === matching, multiple when values, then/else, return value, common gotchas.

  3. Ruby keyword: class

    The Ruby class keyword defines, reopens, and extends classes — including singleton classes via class << obj. Syntax, return value, and gotchas.

  4. Ruby keyword: def

    The def keyword defines methods in Ruby — instance, class, singleton, and operator methods — with positional, keyword, splat, and block parameters.

  5. Ruby keyword: if

    Ruby if expression: syntax for if, elsif, else, ternary, and modifier-if forms, with truthy rules and return value behavior.

  6. Ruby keyword: module

    The Ruby module keyword creates a Module for namespacing and mix-ins. Covers syntax, nesting, reopening, and gotchas vs class.

  7. Ruby keyword: unless

    Ruby unless expression: block form, modifier form, else rules, truthy/falsy rules, return value, and common parser gotchas.

  8. Ruby keyword: until

    Ruby's until keyword loops while a condition is false. Block form, modifier form, begin/end variant, return value, and break/next/redo interaction.

  9. Ruby keyword: when

    Ruby when clause inside case: === matching, multiple patterns per when, then/else, regex/range/module/proc matchers, and how it differs from if.

  10. Ruby keyword: while

    Ruby's while keyword loops while a condition stays true. Syntax, modifier form, begin/end variant, return value, and break/next/redo interaction.