diff options
| author | BurdetteLamar <burdettelamar@yahoo.com> | 2025-02-16 11:35:31 -0600 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-02-16 13:01:17 -0500 |
| commit | 2b69949407a4872e317dbc50dd1d3a6b1c72752a (patch) | |
| tree | d6a4bb87474be58e02c99a37632ae5f8acdb2a4a | |
| parent | 0a10c9bed6f20e63a7cc19e9e4778f9a996aaf1a (diff) | |
[DOC] Tweaks for Hash#delete
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12758
| -rw-r--r-- | hash.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -2403,26 +2403,33 @@ rb_hash_delete(VALUE hash, VALUE key) * delete(key) -> value or nil * delete(key) {|key| ... } -> object * - * Deletes the entry for the given +key+ and returns its associated value. + * If an entry for the given +key+ is found, + * deletes the entry and returns its associated value; + * otherwise returns +nil+ or calls the given block. + * + * With no block given and +key+ found, deletes the entry and returns its value: * - * If no block is given and +key+ is found, deletes the entry and returns the associated value: * h = {foo: 0, bar: 1, baz: 2} * h.delete(:bar) # => 1 * h # => {foo: 0, baz: 2} * - * If no block given and +key+ is not found, returns +nil+. + * With no block given and +key+ not found, returns +nil+. + * + * With a block given and +key+ found, ignores the block, + * deletes the entry, and returns its value: * - * If a block is given and +key+ is found, ignores the block, - * deletes the entry, and returns the associated value: * h = {foo: 0, bar: 1, baz: 2} * h.delete(:baz) { |key| raise 'Will never happen'} # => 2 * h # => {foo: 0, bar: 1} * - * If a block is given and +key+ is not found, + * With a block given and +key+ not found, * calls the block and returns the block's return value: + * * h = {foo: 0, bar: 1, baz: 2} * h.delete(:nosuch) { |key| "Key #{key} not found" } # => "Key nosuch not found" * h # => {foo: 0, bar: 1, baz: 2} + * + * Related: see {Methods for Deleting}[rdoc-ref:Hash@Methods+for+Deleting]. */ static VALUE |
