Ruby Tutorial: Collections

Collections

  • Arrays
  • Hashes
  • Ranges

Ref. WGR Chapter 9, Collection and container objects

Array vs. Hash


  • An array is an ordered list of values
  • A hash is an unordered set of key/value pairs

  • An array has an index that must be an integer
  • A hash has a key that can be any object (number, string, another hash, etc.)

  • Array is also called List, Vector
  • Hash is also called Map, Dictionary

  • Array literals are defined with [ ]
  • Hash literals are defined with { }
  • both are accessed with [ ]