You can create an array by listing some items within
square brackets ([]) and separating them with
commas. Ruby's arrays can accomodate diverse object types.
ruby> ary = [1, 2, "3"] [1, 2, "3"]
Arrays can be concatenated or repeated just as strings can.
An associative array has elements that are accessed not by
sequential index numbers, but by keys which can have any sort
of value. Such an array is sometimes called a hash or
dictionary; in the ruby world, we prefer the term
hash. A hash can be constructed by quoting pairs of items
within curly braces ({}). You use a key to find
something in a hash, much as you use an index to find something in an
array.
ruby> h = {1 => 2, "2" => "4"} {1=>2, "2"=>"4"}
ruby> h[1] 2
ruby> h["2"] "4"
ruby> h[5] nil
ruby> h[5] = 10 # appending value 10
ruby> h {5=>10, 1=>2, "2"=>"4"}
ruby> h.delete 1 # deleting value 2
ruby> h[1] nil
ruby> h {5=>10, "2"=>"4"}