10.3. Enumerable searching and selecting

It’s common to want to filter a collection of objects based on one or more selection criteria. For example, if you have a database of people registering for a conference, and you want to send payment reminders to the people who haven’t paid, you can filter a complete list based on payment status. Or you might need to narrow a list of numbers to only the even ones. And so forth; the use cases for selecting elements from enumerable objects are unlimited.

The Enumerable module provides several facilities for filtering collections and for searching collections to find one or more elements that match one or more criteria. We’ll look at several filtering and searching methods here. All of them are iterators: ...

Get The Well-Grounded Rubyist, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.