From: "phluid61 (Matthew Kerwin)" Date: 2013-02-07T08:22:05+09:00 Subject: [ruby-core:51952] [ruby-trunk - Feature #6641] Hash.auto constructor Issue #6641 has been updated by phluid61 (Matthew Kerwin). I agree with nobu-shi, if I were to encounter `Hash::with_default &block` I would assume it was the equivalent of: Hash.new{ |h,k| yield } rather than: Hash.new{ |h,k| h[k] = yield } Perhaps there could be ::with_default and ::with_default! ---------------------------------------- Feature #6641: Hash.auto constructor https://bugs.ruby-lang.org/issues/6641#change-35951 Author: trans (Thomas Sawyer) Status: Open Priority: Normal Assignee: Category: core Target version: next minor =begin It is not uncommon to need a Hash following the pattern: Hash.new{ |h,k| h[k]={} } Another common example: Hash.new{ |h,k| h[k]=[] } This is common enough that it would very nice if we could have a more concise form, e.g. Hash.auto{ {} } Or for the second example: Hash.auto{ [] } Pure Ruby implementation is pretty simple: def Hash.auto Hash.new{ |h,k| h[k] = yield } end I think it would be nice to have in Core. This is secondary, but it just occurred to me. Could there even be a literal notation for the above? Something like: {}([]) ? =end -- http://bugs.ruby-lang.org/