liveBook · Manning

All_with_* method pattern

As explained in The Well-Grounded Rubyist, Fourth Edition

The all_with_* method pattern is a naming scheme in which a method prefix identifies an attribute whose matching objects should be searched.

The all_with_* pattern turns missing class-method calls into searches. For example, Person.all_with_friends(person) finds people whose friends include that person, while Person.all_with_hobbies("rings") finds matching hobby owners. section 4.3.1

Searching stored relationships

After John and George both befriend Paul, Person.all_with_friends(p) reports John and George. After Ringo records "rings" as a hobby, Person.all_with_hobbies("rings") reports Ringo.

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains prefix parsing, attribute validation, collection filtering, error handling, and delegation through super.
Examples
Uses Person friends and hobbies, including searches for Paul and "rings", with printed matching names.
What it assumes
Assumes familiarity with Ruby classes, methods, collections, method_missing, and super.
What you can do after
Build dynamic class-level searches that validate derived attributes and preserve normal missing-method behavior.
How it connects
Connects method_missing with class methods, method lookup, super, and dynamic dispatch.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.