--- ---

Ruby Development Style Guide

Ruby coding styles and conventions for DocOps Lab projects.

This guide outlines the Ruby coding styles and conventions used in DocOps Lab projects.

Automated Style Enforcement

DocOps Lab projects using the docopslab-dev gem automatically enforce Ruby style guidelines through:

RuboCop

Automated code style checking and auto-fixing

Git Hooks

Pre-commit advisory checks, pre-push quality gates

CI/CD Integration

Automated linting in GitHub Actions workflows

To apply style fixes: bundle exec rake labdev:heal:ruby

See DocOps Lab Dev-tooling Usage for setup details.

Conventions

DocOps Lab largely follows Ruby’s community conventions, with some exceptions. Conventions are either reiterated or clarified here.

However, conventions are not exhaustively listed, and deviations are rarely pointed out as such.

Naming Conventions

  • Use snake_case for variable and method names.

  • Use CamelCase for class and module names.

  • Use SCREAMING_SNAKE_CASE for constants.

  • Use descriptive names that convey the purpose of the variable, method, or class.

  • Avoid abbreviations unless they are widely understood.

  • Use verbs for method names to indicate actions.

  • Use nouns for class and module names to indicate entities.

Architectural Conventions

  • Use classes and class instance methods for objects that work like objects — they have state and do not act on other objects' state.

  • Use module methods acting on objects or carrying out general operations/utility functions.

  • Use Rake for internal (developer) CLI; use Thor for user-facing CLI

  • Gems may begin life as a module within another gem.

Path Conventions

  • Use lib/ for main application code.

    • lib/<project_name>.rb for the main file

    • lib/<project_name>/ for supporting files and modules

    • lib/<project_name>/<module_name>/ for submodules

  • Use spec/ for specifications and tests.

  • Use docs/ or _docs/ for documentation.

  • Use build/ for pre-runtime artifacts.

  • Use _build/ as default in applications that generate files at runtime, unless another path is more appropriate (ex: _site/ in Jekyll-centric apps).

  • Do NOT assume or insist upon perfect alignment with Ruby path conventions:

    • SomeModule or SomeClass may be sourced at lib/some_module.rb or lib/some_class.rb instead of lib/some/module.rb or lib/some/class.rb.

    • Some modules like SchemaGraphy and AsciiDoc are never broken up into schema_graphy or ascii_doc namespaces.

    • Modules with multiple parallel sibling modules in a category like (WriteOps, DraftOps) belong in paths like lib/ops/write.rb instead of lib/write_ops.rb or lib/write/ops.rb.

Syntax Conventions

  • Use 2 spaces for indentation.

  • Limit lines to 120 characters or so when possible.

  • Use parentheses for method calls with arguments, but omit them for methods without arguments.

  • Do not use parentheses in method definitions (def method_name arg1, arg2).

  • Use single quotes for strings that do not require interpolation or special symbols.

  • Use double quotes for strings that require interpolation or special symbols.

Commenting Conventions

See DocOps Lab Code Commenting Guidance for detailed commenting conventions.

RuboCop Customization

These rules (“cops”) can be overridden on a per-project basis in the .config/rubocop.yml file. See RuboCop Configuration for docopslab-dev-managed RuboCop configuration.

Project Ruby Style Guide (Customizations Only)

This document lists only deviations from the standard RuboCop defaults. For everything else, consult: RuboCop Style Guide (All Cops)

Generated from gems/docopslab-dev/assets/config-packs/rubocop/base.yml compared to built-in defaults.

All Cops

Display Style Guide

true

New Cops

enable

Target Ruby Version

3.2

Layout: First Method Argument Line Break

Enabled

true

Layout: Hash Alignment

Enabled

false

Layout: Line Length

Allowed Patterns
  • \A\s*#.*\z

  • \A\s**.*\z

Layout: Multiline Method Call Brace Layout

Enforced Style

same_line

Layout: Parameter Alignment

Enforced Style

with_fixed_indentation

Layout: Space Around Equals In Parameter Default

Enabled

false

Enforced Style

no_space

Layout: Space Around Operators

Enabled

false

Metrics: Abc Size

Enabled

false

Metrics: Block Length

Allowed Methods
  • describe

  • context

  • feature

  • scenario

  • let

  • let!

  • subject

  • task

  • namespace

Max

50

Metrics: Cyclomatic Complexity

Enabled

false

Metrics: Method Length

Max

25

Metrics: Perceived Complexity

Enabled

false

Naming: Predicate Method

Enabled

false

Security: YAMLLoad

Enabled

false

Style: Comment Annotation

Keywords
  • TODO

  • FIXME

  • OPTIMIZE

  • HACK

  • REVIEW

Style: Commented Keyword

Enabled

false

Style: Documentation

Enabled

false

Style: Method Call With Args Parentheses

Allow Parentheses In Chaining

true

Allow Parentheses In Multiline Call

true

Style: Method Def Parentheses

Enforced Style

require_no_parentheses

RuboCop Configuration

Ruby code style and quality checking.

Base config

.config/.vendor/docopslab/rubocop.yml

Project config

.config/rubocop.yml (inherits via inherit_from)

Sync command

bundle exec rake labdev:sync:configs

The base configuration provides DocOps Lab Ruby style standards. Your project config can override any rule while maintaining consistency with the broader ecosystem.