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.
What you will learn
- Preserve data meaning and behavior across reusable method and model boundaries.
Control block, Proc, and lambda lifetimes
Read closure capture, argument handling, non-local return, and synchronous invocation before storing or reusing callbacks.
Start learningBuild Enumerable pipelines with deliberate evaluation
Use selection, mapping, grouping, aggregation, and lazy enumeration while preserving false values, bounded work, and effect ownership.
Start learningTranslate exceptions without hiding failures
Use narrow rescue clauses, explicit rejection, preserved causes, and ensure cleanup while keeping successful data distinct from fallback.
Start learningCompose modules through a visible method lookup contract
Distinguish namespaces, include, extend, prepend, and super while avoiding broad monkey patches and hidden lifecycle changes.
Start learningChoose Data or Struct with explicit value semantics
Understand generated members, shallow value objects, with copies, eql?/hash contracts, and stable collection keys.
Start learningMatch 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