6.4 Summary

We discussed one-dimensional arrays, arrays of arrays, and hashes. These are constructs that often take students time to learn, so we strongly suggest that you work through all the exercises in this chapter to ensure that you have a full understanding of these concepts.

6.4.1 Key Concepts

  • Arrays are structures that use a table format to store variables. The data stored in an array is accessed using numbers as an index starting at 0. They can be used in any programming structure, but they are most commonly associated with the loop structure.

  • One key concept when working with arrays is that they can have an infinite number of dimensions. This means that a memory location within an array can either store a single piece of data or store an entirely new array.

  • Hashes are much like arrays, except that rather than using only an integer to look up a memory location, any variable can be used as a key.

6.4.2 Key Definitions

  • Array: A consecutively numbered list of variables.

  • Element: A variable contained within an array.

  • Multidimensional array: An array whose elements are also arrays.

  • Index: The number associated with a certain element within an array.

  • Traverse: To move from one element to another within an array.

  • Hash: A data structure that can map any data type (key) to a value.

Get Computer Science Programming Basics in Ruby 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.