Chapter 8. Arrays, Hashes, and Other Enumerables
Simple variables are not adequate for real-life programming. Every modern language supports more complex forms of structured data and also provides mechanisms for creating new abstract data types. Historically, arrays are the earliest known and most widespread of the complex data structures. Long ago, in FORTRAN, they were called subscripted variables; today they have changed somewhat, but the basic idea is the same in all languages. More recently, the hash has become an extremely popular programming tool. Like the array, it is an indexed collection of data items; unlike the array, it may be indexed by any arbitrary object. (In Ruby, as in most languages, array elements are accessed by a numerical index.) Finally, we'll take a more general look at the Enumerable module itself and how it works. Arrays and hashes both mix in this module, as can any other class for which this functionality makes sense. But let's not get ahead of ourselves. We will begin with arrays. |