Array
Arrays are ordered, integer-indexed collections that may contain any Ruby object. The objects in the array do not need to be of the same type. They can be created using the literal square bracket syntax discussed in Chapter 4, Collections, Blocks, and Iterators. The %w delimiter with a space-delimited list can create an array of strings, and %i can similarly create an array of symbols. The Array.new(size, default = nil) method creates a new array with the given size and populated with the default object. The Kernel#Array(object) method converts its argument into an array if the argument isn’t already an array.
Arrays implement Array#each [{ |element| block}] and mix in the Enumerable module, so all methods of Enumerable described in ...
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