Filed In:
Enumerable: Working with Collections
Most languages have the concept of a "collection," or objects that hold other objects. In Ruby, this concept is expressed as the Enumerable mixin.
Enumerable: Picking Out Just What You Want
The Enumerable mixin provides a collection interface to all manner of collections in Ruby. A collection is just what it sounds like, any object that holds a collection of other objects. Common collections in Ruby are the Array and Hash, but anything that holds objects and implements the each method to iterate over them can use the Enumerable mixin.
Enumerable: Do Any or All Objects Match?
Another useful thing to do with collections is see if any or all of the elements match a certain criteria. For example, if I’m gathering temperature data, I want to sound an alarm if any temperature in an array is over 100 degrees. I want to shut down the system I’m monitoring if all of the temperatures in the sample are over 100 degrees.
