Global variables in Ruby use a $ prefix, stay visible across scopes, and should be reserved for rare program-wide state.
Reference
Keywords
Ruby keywords and special language constructs.
- Global Variables
- Ruby keyword: case
Ruby case expression: subject form vs no-subject form, === matching, multiple when values, then/else, return value, common gotchas.
- Ruby keyword: class
The Ruby class keyword defines, reopens, and extends classes — including singleton classes via class << obj. Syntax, return value, and gotchas.
- Ruby keyword: def
The def keyword defines methods in Ruby — instance, class, singleton, and operator methods — with positional, keyword, splat, and block parameters.
- Ruby keyword: if
Ruby if expression: syntax for if, elsif, else, ternary, and modifier-if forms, with truthy rules and return value behavior.
- Ruby keyword: module
The Ruby module keyword creates a Module for namespacing and mix-ins. Covers syntax, nesting, reopening, and gotchas vs class.
- Ruby keyword: unless
Ruby unless expression: block form, modifier form, else rules, truthy/falsy rules, return value, and common parser gotchas.
- 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.
- 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.
- 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.