Adding new keys to a Array Of Hashes

Solution 1:

I would probably:

  1. Use map to iterate over the elements in list and build a new array at the same time
  2. Since each element is a hash with one item, destruct that into a key and value
  3. Build the new hash in the correct format
new_list = list.map do |hash|
  # e.g. key = "Mary", value = "Die Hard"
  key, value = hash.first

  {name: key, film: value}
end

This assumes that each hash in the list will have only one item (as you've shown in your example in the question) - you may want to validate this elsewhere, since this solution would ignore any other items in the hash past the first.