A hash ( associative array or a dictionary) is an array holding a collection of data, : Hash Creation « Hash « Ruby






A hash ( associative array or a dictionary) is an array holding a collection of data,


# you can index it using text strings as well as numbers.

# To create a hash, you use curly braces, { and }, not square braces ([]) as with arrays. 

money = {"Dan" => "$1,000,000", "Mike" => "$500,000"}

# "Dan" is a hash key 
# "$1,000,000" is the value. 
# The => operator separates the keys from the values.

 








Related examples in the same category

1.Hashes use braces instead of brackets to let the Ruby interpreter know what is being created.
2.Hash has a class method [], which is called in either one of two ways: with a comma separating the pairs
3.Instead of integers, you could use strings for the keys
4.The hash definition is enclosed in curly braces, whereas an array is defined in square brackets.
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