Chapter 9. Collection and container objects

 

In this chapter

  • Sequentially ordered collections with arrays
  • Keyed collections with hashes
  • Inclusion and membership tests with ranges
  • Unique, unordered collections with sets

 

In programming generally, you deal not only with individual objects but with collections of objects. You search through collections to find an object that matches certain criteria (like a magazine object containing a particular article); you sort collections for further processing or visual presentation; you filter collections to include or exclude particular items; and so forth. All of these operations, and similar ones, depend on objects being accessible in collections.

Ruby represents collections of objects by putting ...

Get The Well-Grounded Rubyist now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.