← Graph

Specifying types at the method boundary with pattern matching

question 1 connections

Audience asks how to declare types for a public method's arguments. Drapper's answer: use Ruby's pattern matching in the method body (first-line case/in). He's explored method-level type-check APIs but hasn't found one he loves. In practice, checking at object boundaries via props gives most of the value; if you really want method-level types, wrap the call into a service object or rely on pattern matching.

answer_summary
Use Ruby pattern matching at the top of the method. Drapper hasn't found a satisfying method-level API; object-boundary checks via props cover most cases.
question Specifying types at the method boundary with pattern matching
asked_at
Third audience Q&A question about method-level typing.

Provenance