programming.nbk: Home | Index | Next Page: Ruby: if-then-else | Previous Page: Ruby: for


 Ruby: Hashes

Hashes are also known as associative arrays or dictionaries.

Hashes are indexed by other objects, not neccessarily integers.

    h = { 'dog' => 'canine', 'cat' => 'feline', 'donkey' => 'asinine' }  
 
    h.length  » 3  
    h['dog']  » "canine"  
    h['cow'] = 'bovine'  
    h[12]    = 'dodecine'  
    h['cat'] = 99  
    h  » {"cow"=>"bovine", "cat"=>99, 12=>"dodecine", "donkey"=>"asinine", "dog"=>"canine"}

programming.nbk: Home | Index | Next Page: Ruby: if-then-else | Previous Page: Ruby: for


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time