class
Importance_2
Ruby latest stable (v1_8_7_72) - 1 note - Superclass: Object

Arrays are ordered, integer-indexed collections of any object. Array indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array—that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.

Show files where this class is defined (6 files)
Register or log in to add new notes.
February 12, 2009
3 thanks

Literal syntax

As you propably know you can create an Array either with the constructor or the literal syntax:

  Array.new == []
  # => true

But there is also another nice and concise literal syntax for creating Arrays of Strings:

  ["one", "two", "three"] == %w[one two three]
  # => true

You can use any kind of parenthesis you like after the %w, either (), [] or {}. I prefer the square brackets because it looks more like an array.