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 ...
Get Programming Ruby 3.3 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.