8.1. Working with Arrays
Arrays in Ruby are indexed by integers and are zero-based, just like C arrays. There the resemblance ends, however.
A Ruby array is dynamic. It is possible (but not necessary) to specify its size when you create it. After creation, it can grow as needed without any intervention by the programmer.
A Ruby array is heterogeneous in the sense that it can store multiple data types rather than just one type. Actually, it stores object references rather than the objects themselves, except in the case of immediate values such as Fixnums.
An array keeps up with its own length so that we don’t have to waste our time calculating it or keeping an external variable in sync with the array. Iterators also are defined so that, in practice, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access