Arrays

Arrays and hashes are perhaps the two data structures that will be used the most by developers who are writing the Chef code. Be it fetching attributes or values from data bags, you'll be finding these two data structures almost everywhere.

Arrays are an ordered collection of objects that can be accessed through an integer index. Each element of an array can be referenced through an index. The first element of the array is referenced through index number 0 and so on. Ruby also provides support for negative integers as indexes. -1 refers to the last element of the array, -2 is the second last element, and so on.

Unlike other languages, arrays in Ruby aren't tied to one single data type, and they aren't fixed in size either. Ruby arrays grow ...

Get Mastering Chef 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.