In Ruby, Enumerable is a module that provides a collection of methods to traverse,
filter, and manipulate elements within a collection (e.g., arrays, hashes) or
any class that implements the each method. This module is included in several
built-in Ruby classes, such as Array, Hash, Range, and Set, enabling them to access
a wide range of powerful methods.
Here are some commonly used methods from Enumerable:
each: The most fundamental method required by Enumerable. It allows you to iterate over each element in the collection.
map (or collect): Transforms each element in the collection according to the block provided, returning a new array with the results.
select (or find_all): Filters elements based on the condition given in the block, returning a new array with the elements that meet the criteria.
reduce (or inject): Combines all elements of the collection into a single value by applying the block's operation cumulatively.
any?: Returns true if at least one element in the collection satisfies the condition in the block.