Chapter 9. More Advanced Data Structures

A graphic representation of data abstracted from the banks of every computer in the human system. Unthinkable complexity. Lines of light ranged in the nonspace of the mind, clusters and constellations of data. Like city lights, receding.

—William Gibson

There are, of course, more complex and interesting data structures than arrays, hashes, and their cousins. Some of the ones we’ll look at here have direct or indirect support in Ruby; others are “roll-your-own” for the most part. Fortunately, Ruby simplifies the construction of custom data structures.

The mathematical set can be dealt with by means of arrays, as we’ve already seen. But recent versions of Ruby have a Set class that serves this purpose well. ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Third Edition 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.