Feature #19128
closed
Since you are avoiding doing:
{}.delete(:a) || []
it must be the case that you have a hash in which nil
can be a meaningful value, and you want to distinguish that from the case where delete
results in a miss hit. What is the use case for that?
@dorianmariefr (Dorian Marié) 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 (Nobuyoshi Nakada) 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.
You can close this, passing a block is much nicer and provides the functionality I need.
As a side note, I think passing multiple arguments could delete multiple keys from the hash but I don't have the use for it.
- Status changed from Open to Rejected
Also available in: Atom
PDF
Like1
Like0Like0Like0Like0Like0