I want to remove the spaces in the key value in the hashes
output = [
{"first name"=> "george", "country"=>"Australia"},
{"second name"=> "williams", "country"=>"South Africa"},
{"first name"=> "henry", "country"=>"US"}]
I was able to manage when only one hash was there inside the array with the following code
Array.wrap({}.tap do |hash|
output.each do |key|
key.each do |k, v|
hash[k.gsub(" ","_")] = v
end
end
end)
Please help me to modify the array containing more than one hash.
Note: the output value is dynamic that we cannot hardcode the hash key in the code.