|
As arrays, Hashes are used for storing data also.Hashes map an object to another object, think of assigning a string a certain "meaning" in your program; and each time you refer that string, you actually refer to it's meaning.
How to create an empty hash:
same as when creating an empty array: using the "new" method:
pizza = Hash.new
Or by using the curly brackets:
pizza = {
'marguerita' => 'tomato sauce and cheese',
'quattro formaggi' => 'mozzarella,gorgonzola,parmigiano and ricotta',
'quattro stagioni' => 'prosciutto, mozzarella, parmigiano,mushrooms,clams'
}
This is how you find out to what each "key" in the hash is associated with:
pizza['marguerita']
|