Ruby Enumerable Mixin Explained
Modules that you include into classes are also called Mixins. Once more, classes are defined so that objects can be instantiated off of them and modules are lacking this capability.
There are couple of important considerations when using modules from within classes. You can access all of the module methods after including it into class. However, if you include more than one module into class and these modules have method with the same name, only one method will be called from within the class. This method belongs to last included module.
One the useful Mixins in Rube is Enumerable module. You can gain over 22 useful methods by including this module into your class. Enumerable is the most common mixin in Ruby language as well. It helps you set up any data structure with capability to iterate over it. In fact, a lot of standard classes such as Dir, Hash, and String include Enumerable mixin in its implementations.
All of the methods available to you after inclusion of enumerable mixin are:
chunk
collect_concat
count
cycle
drop
drop_while
each_cons
each_entry
each_slice
each_with_object
find_index
first
flat_map
group_by
lazy
max_by
min_by
minmax
minmax_by
none?
one?
reduce
reverse_each
slice_before
take
take_while