> 
> **Note**: There were a few similar questions on SO about this, like [here](https://stackoverflow.com/questions/10647905/create-nested-hashes-from-a-list-of-hashes-in-ruby)
>  and [here](https://stackoverflow.com/questions/5095077/ruby-convert-array-to-nested-hash), but none seem quite like what I'm looking for.
> 
> 
> 

Say I have an array of hashes like this:

```
arr_with_dup_hsh_keys = [
  { foo: "dup", bar: 1 },
  { foo: "dup", bar: 2 },
  { foo: "dup", bar: 3 },
  { foo: "dup", bar: 4 },
  { foo: "dup", bar: 5 }
]

```

How do I reduce that down to this?

```
{ foo: "dup", bars: [1, 2, 3, 4, 5] }

```

And what if there are different values for `foo`?

```
arr_with_dup_hsh_keys = [
  { foo: "dup",  bar: 1 },
  { foo: "dup",  bar: 2 },
  { foo: "soup", bar: 3 },
  { foo: "dup",  bar: 4 },
  { foo: "soup", bar: 5 }
]

```