Project

General

Profile

Actions

Feature #9929

open

add with_default method to Hash

Added by dontfidget (Andrew Brown) almost 10 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:63085]

Description

I would like to be able to write this:

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

instead of:

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

or, perhaps:

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

Just wondering if anyone else would be interested in a change like this. I posted a pull request in Rails for an ActiveSupport core extension that does the same thing but would love to see it in Ruby proper. (Pull request is at https://github.com/rails/rails/pull/15626)

No data to display

Actions

Also available in: Atom PDF

Like0