Skip to content

Instantly share code, notes, and snippets.

@adampats
Created September 1, 2015 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampats/388154b23b1d9d0f33bd to your computer and use it in GitHub Desktop.
Save adampats/388154b23b1d9d0f33bd to your computer and use it in GitHub Desktop.
Combine two arrays of hashes
a = [
{ key: "key1", value: "value1" },
{ key: "key2", value: "value2" }
]
b = [
{ key: "key3", value: "value3" },
{ key: "key4", value: "value4" }
]
a.push(b)
### Output
[{:key=>"key1", :value=>"value1"}, {:key=>"key2", :value=>"value2"}, [{:key=>"key3", :value=>"value3"}, {:key=>"key4", :value=>"value4"}]]
### What I need (no nested arrays)
[{:key=>"key1", :value=>"value1"}, {:key=>"key2", :value=>"value2"}, {:key=>"key3", :value=>"value3"}, {:key=>"key4", :value=>"value4"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment