Join hash keys together : Hash Keys « Hash « Ruby






Join hash keys together


hash = { "key1" => "val1", "key2" => "val2" }
string = ""
hash.each { |k,v| string << k << " is " << v << "\n" }
puts hash.keys.join("\n") + "\n"
puts string

 








Related examples in the same category

1.Return an array containing all the keys in a hash with keys:
2.Extract data from the hash by using its keys.
3.Use number as hash key
4.Retrieving Keys
5.RuntimeError: hash modified during iteration
6.Get all keys from a hash
7.Time value key
8.Searching a Hash with Regular Expressions
9.What if a key does not exist
10.Hash as a key