@@ -2403,26 +2403,33 @@ rb_hash_delete(VALUE hash, VALUE key)
24032403 * delete(key) -> value or nil
24042404 * delete(key) {|key| ... } -> object
24052405 *
2406- * Deletes the entry for the given +key+ and returns its associated value.
2406+ * If an entry for the given +key+ is found,
2407+ * deletes the entry and returns its associated value;
2408+ * otherwise returns +nil+ or calls the given block.
2409+ *
2410+ * With no block given and +key+ found, deletes the entry and returns its value:
24072411 *
2408- * If no block is given and +key+ is found, deletes the entry and returns the associated value:
24092412 * h = {foo: 0, bar: 1, baz: 2}
24102413 * h.delete(:bar) # => 1
24112414 * h # => {foo: 0, baz: 2}
24122415 *
2413- * If no block given and +key+ is not found, returns +nil+.
2416+ * With no block given and +key+ not found, returns +nil+.
2417+ *
2418+ * With a block given and +key+ found, ignores the block,
2419+ * deletes the entry, and returns its value:
24142420 *
2415- * If a block is given and +key+ is found, ignores the block,
2416- * deletes the entry, and returns the associated value:
24172421 * h = {foo: 0, bar: 1, baz: 2}
24182422 * h.delete(:baz) { |key| raise 'Will never happen'} # => 2
24192423 * h # => {foo: 0, bar: 1}
24202424 *
2421- * If a block is given and +key+ is not found,
2425+ * With a block given and +key+ not found,
24222426 * calls the block and returns the block's return value:
2427+ *
24232428 * h = {foo: 0, bar: 1, baz: 2}
24242429 * h.delete(:nosuch) { |key| "Key #{key} not found" } # => "Key nosuch not found"
24252430 * h # => {foo: 0, bar: 1, baz: 2}
2431+ *
2432+ * Related: see {Methods for Deleting}[rdoc-ref:Hash@Methods+for+Deleting].
24262433 */
24272434
24282435static VALUE
0 commit comments