Skip to content

Instantly share code, notes, and snippets.

@tahb
Created July 2, 2014 14:06
Show Gist options
  • Save tahb/a428dfc90491e70821c4 to your computer and use it in GitHub Desktop.
Save tahb/a428dfc90491e70821c4 to your computer and use it in GitHub Desktop.
Iterating over and modifying hashes inside an array
hash = Hash[key: "value1", key: "value2"]
hash2 = Hash[key: "value1", anotherkey: "value2"]
array = [hash, hash2]
array.each { |hash| hash.inject({}) { |h, (k,v)| h[k] = "blue"; h} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment