0001 # 0002 # Example of Ruby hash 0003 # 0004 scarborough = { # declare and initialize a hash table 0005 "P"=>"parsley", 0006 "S"=>"sage", 0007 "R"=>"rosemary", 0008 "T"=>"thyme" 0009 } 0010 puts scarborough # output the hash table 0011 puts "\n" 0012 for k in scarborough.keys # output hash table items 0013 puts k + "=>" + scarborough[k] # 1-by-1 0014 end 0015 puts "\n" 0016 for k in scarborough.keys.sort # output sorted hash table items 0017 puts k + "=>" + scarborough[k] # 1-by-1 0018 end