O'Reilly logo

The Well-Grounded Rubyist by David A. Black

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Collections central: Enumerable and Enumerator

 

In this chapter

  • Mixing Enumerable into your classes
  • The use of Enumerable methods in collection objects
  • Strings as quasi-enumerable objects
  • Sorting enumerables with the Comparable module
  • Enumerators

 

All collection objects aren’t created equal—but an awful lot of them have many characteristics in common. In Ruby, common characteristics among many objects tend to reside in modules. Collections are no exception: collection objects in Ruby typically include the Enumerable module.

Classes that use Enumerable enter into a kind of contract: the class has to define an instance method called each, and in return, Enumerable endows the objects of the class with all sorts of collection-related ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required