hash1 = { 1 => "one", 2 => "two", 3 => "three" } hash2 = Hash[ 3 => "three", 4 => "four", 5 => "five" ] hash3 = Hash[ 6, "six", 7, "seven", 8, "eight" ] # make a pretty hash function class Hash def format data = self.keys.collect do |key| key = "#{key} => #{self[key]}" end "{ #{data.join( ', ' )} }" end end # useful hash functions hash1.each_pair do |key, value| puts "#{key} => #{value}" end # print the hash keys puts "Keys: [ #{hash1.keys.join( ', ' )} ]" # print the formatted hash puts hash1.format # directly accessing a hash puts hash1[ 2 ]