ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "byroot (Jean Boussier)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110753] [Ruby master Feature#19128] Hash#delete could take a second argument as the default value?
Date: Mon, 14 Nov 2022 12:03:38 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-100091.20221114120337.48480@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19128.20221112161018.48480@ruby-lang.org

Issue #19128 has been updated by byroot (Jean Boussier).


@dorianmariefr if you wish for this feature to be considered, you'll need to expand a bit on your description. Like providing a few snippets of code that show how it is helpful, how often and how it makes your code better. Bonus point if you can link to open source code that would benefit from this.

Once that is said, I personally wanted this a bunch of time. As mentioned by others, in most case `hash.delete(:foo) || default` works fine, but sometimes explicit `nil` or `false` may be expected, in which case you have to use `hash.delete(:foo) if hash.key?(:foo)`.

Also as @nobu mentioned, `Hash#delete` already handle a "default block" like fetch, so I think it would make sense to accept a positional default too, just for consistency's sake.

----------------------------------------
Feature #19128: Hash#delete could take a second argument as the default value?
https://bugs.ruby-lang.org/issues/19128#change-100091

* Author: dorianmariefr (Dorian Marié)
* Status: Open
* Priority: Normal
----------------------------------------
e.g. `{}.delete(:a, [])` would return `[]`



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2022-11-14 12:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 16:10 [ruby-core:110725] [Ruby master Feature#19128] Hash#delete could take a second argument as the default value? dorianmariefr
2022-11-13  2:30 ` [ruby-core:110734] " sawa (Tsuyoshi Sawada)
2022-11-14 10:26 ` [ruby-core:110751] " nobu (Nobuyoshi Nakada)
2022-11-14 12:03 ` byroot (Jean Boussier) [this message]
2022-11-24  9:16 ` [ruby-core:110872] " dorianmariefr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-100091.20221114120337.48480@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-core@neon.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).