RU

Ruby Defaults

Core Ruby coding conventions

Details

Language / Topic
rubyRuby
Category
Style Guide

Rules

balanced
- Follow Ruby community conventions: `snake_case` for methods and variables, `PascalCase` for classes and modules.
- Use Ruby 3.0+ features: pattern matching, endless methods, typed signatures with RBS/Sorbet.
- Use `freeze` on string constants: `MY_CONST = 'value'.freeze` — or add `# frozen_string_literal: true` magic comment at the top of each file.
- Use blocks and `yield` for iteration patterns — prefer `each`, `map`, `select` over manual loops.
- Prefer blocks, procs, and lambdas for functional patterns. Use `&method(:name)` for method references.
- Use `freeze` on string literals. Enable `# frozen_string_literal: true` at the top of every file.
- Use `Enumerable` methods (`.map`, `.select`, `.reduce`) over manual loops.
- Raise specific exceptions (`ArgumentError`, `RuntimeError`, custom errors) — never bare `raise`.
- Keep methods under 15 lines. Keep classes focused on a single responsibility.