← Graph

Use Parts To Guarantee Non-Nil Collections

takeaway 2 connections

Practical insight from the Hanami View refactor: by decorating the form hash with a RegistrationFormPart that defines an `errors(name)` method, templates never have to deal with nil or call `to_a` — the decorator guarantees the shape (always an array). Encapsulating these small guarantees in Ruby objects keeps templates readable and the logic unit-testable.

type
insight
takeaway Use Parts To Guarantee Non-Nil Collections
about
Practical pattern using parts
takeaway Use Parts To Guarantee Non-Nil Collections
from_talk
Derived from the parts/errors method example

Provenance