Ruby / Contracts: callables, evaluation, failures, and value models

Ruby β€” Contracts: callables, evaluation, failures, and value models

Use callbacks, Enumerable, exceptions, mixins, Data/Struct, and patterns without hidden lifetime or validation assumptions.

6 lessons Β· No account required

What you will learn

  • Preserve data meaning and behavior across reusable method and model boundaries.
  1. Control block, Proc, and lambda lifetimes

    Read closure capture, argument handling, non-local return, and synchronous invocation before storing or reusing callbacks.

    Start learning
  2. Build Enumerable pipelines with deliberate evaluation

    Use selection, mapping, grouping, aggregation, and lazy enumeration while preserving false values, bounded work, and effect ownership.

    Start learning
  3. Translate exceptions without hiding failures

    Use narrow rescue clauses, explicit rejection, preserved causes, and ensure cleanup while keeping successful data distinct from fallback.

    Start learning
  4. Compose modules through a visible method lookup contract

    Distinguish namespaces, include, extend, prepend, and super while avoiding broad monkey patches and hidden lifecycle changes.

    Start learning
  5. Choose Data or Struct with explicit value semantics

    Understand generated members, shallow value objects, with copies, eql?/hash contracts, and stable collection keys.

    Start learning
  6. Match structured data without overclaiming validation

    Use case/in, type and hash patterns, guards, pins, and explicit mismatch policy under the selected Ruby 3.3 baseline.

    Start learning
Back to course