The hash definition is enclosed in curly braces, whereas an array is defined in square brackets. : Hash Creation « Hash « Ruby






The hash definition is enclosed in curly braces, whereas an array is defined in square brackets.


Each value is associated (=>) with a key. 
One of the ways you can access the values in a hash is by their keys. 

pacific = { "WA" => "Washington", "OR" => "Oregon", "CA" => "California" }


pacific["OR"] # => "Oregon"

 








Related examples in the same category

1.A hash ( associative array or a dictionary) is an array holding a collection of data,
2.Hashes use braces instead of brackets to let the Ruby interpreter know what is being created.
3.Hash has a class method [], which is called in either one of two ways: with a comma separating the pairs
4.Instead of integers, you could use strings for the keys
5.Element Assignment
6.you can store numbers in hashes
7.Using Hashes
8.Creating a Hash with a Default Value
9.Create a hash with default value
10.creates a new default object each time