This section documents Ruby’s collection
classes. A collection is any class that represents a collection of
Hash are the key collection classes in Ruby,
and the standard library adds a
class. Each of these collection classes mixes in the
Enumerable module, which means that
Enumerable methods are universal collection
module is a mixin that implements a number of useful methods
on top of the
each iterator. The
Set classes described below all include
therefore implement all of the methods described here.
IO are other noteworthy enumerable classes.
Enumerable was covered briefly in
Enumerable Objects. This section provides more
Note that some enumerable classes have a natural enumeration
order that their
follows. Arrays, for example, enumerate their elements in order of
increasing array index.
enumerates in ascending order. And
IO objects enumerate lines of text in the
order in which they are read from the underlying file or socket. In
Set (which is based on
Hash) enumerate their elements in the order
in which they were inserted. Prior to Ruby 1.9, however, these classes enumerate their
elements in what is essentially an arbitrary order.
return a processed version of the enumerable collection or a selected
subcollection of its elements. Usually, if an
Enumerable method returns a collection (rather ...