a = [{"a":1},{"b":2}]
I want my output should be
[{ "a":1, "b":2 }]
How to do the format in ruby?
a = [{"a":1},{"b":2}]
I want my output should be
[{ "a":1, "b":2 }]
How to do the format in ruby?
You can achieve this with:
[[{"a":1},{"b":2}].inject(:merge)]
# => [{:a=>1, :b=>2}]
Which iterates over the array and merges each hash, then closes it all in an array. I really doubt you need to close your hash in an array as the last step though.