An array literal constructs an array with square brackets. Write elements between the brackets, separating them with commas; elements may have different types, including another array. section 9.2.1
A mixed array
a = [1, 2, "three", 4, []] creates an array containing integers, a string, and a nested empty array. Ruby also lets you retrieve an element with bracket indexing, as in array[0]. section 9.2.1
a = [1,2,"three",4, []]
Inspect a literal containing several value types and a nested array. section 9.2.1
Square-bracket literals provide a compact alternative to other array-creation forms:
- Use [] for an empty array. section 9.2.1
- Use comma-separated values such as [1, 2, "three"] for an immediately populated array. section 9.2.1
- Distinguish literals from Array.new and specialized %w and %i notations, which create arrays through different syntax or methods. section 9.2.1
