Project

General

Profile

Feature #14128

Introduce Hash#delete default value

Added by gshutler (Garry Shutler) almost 2 years ago. Updated almost 2 years ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:83870]

Description

Mirror Hash#fetch(key [, default]) → obj with Hash#delete(key [, default]) → obj.

Allows for more concise extraction of a value from a hash with a default.

# Currently
a = hash.delete(:a) { 10 }

# Becomes
a = hash.delete(:a, 10)

History

Updated by shevegen (Robert A. Heiler) almost 2 years ago

I think this should be filed under features rather than bugs.

Here is a link to the documentation if anyone else wants to have
a look:

https://ruby-doc.org/core/Hash.html#method-i-delete

I am neither pro or con on the suggestion so I will not
comment on it - I only wanted to provide a quick link to
the docu so that others can find the most recent docu +
examples more easily.

#2

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN)
  • Tracker changed from Bug to Feature

Updated by gshutler (Garry Shutler) almost 2 years ago

Sorry, I thought I was recording it as a feature request. Thanks for fixing nobu.

Updated by marcandre (Marc-Andre Lafortune) almost 2 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

I am in favor of this.

Also available in: Atom PDF