rails/rails — pull request #15626 by dontfidget (2014-06-11 00:00:56+00:00)
Title: add with_default method on Hash

Here's a pull request to add a `with_default` method to the Hash class in ActiveSupport extensions. Really, I'd like to see this in ruby, but rails ActiveSupport extensions seems like a good place to start and I'm not sure how to go about the other.

It's always irked me that I can't write something like this:

```ruby
people.group_by(:first_name).with_default { [] }
```

Instead, I would have to write:

```ruby
hash = people.group_by(:first_name)
hash.default_proc = proc { [] }
```

or, perhaps:

```ruby
people.group_by(:first_name).tap { |hash| hash.default_proc = proc { [] } }
```

Neither of the above lend themselves to readability. I can take this to the mailing list and would welcome any suggestions about how to propose this to the ruby community. Since I do have a concrete offering, I just thought a pull request couldn't hurt. And if I've missed some way better way of doing the same thing, please let me know and I'll happily forget about this. Thanks.