[DOC] Tweaks for Hash#keep_if

This commit is contained in:
BurdetteLamar 2025-02-26 10:22:05 -06:00 committed by Peter Zhu
parent 04e46bd75c
commit 1b6fddf4db
Notes: git 2025-02-26 20:53:02 +00:00

12
hash.c
View File

@ -2836,16 +2836,16 @@ rb_hash_select_bang(VALUE hash)
* keep_if {|key, value| ... } -> self * keep_if {|key, value| ... } -> self
* keep_if -> new_enumerator * keep_if -> new_enumerator
* *
* Calls the block for each key-value pair; * With a block given, calls the block for each key-value pair;
* retains the entry if the block returns a truthy value; * retains the entry if the block returns a truthy value;
* otherwise deletes the entry; returns +self+. * otherwise deletes the entry; returns +self+:
*
* h = {foo: 0, bar: 1, baz: 2} * h = {foo: 0, bar: 1, baz: 2}
* h.keep_if { |key, value| key.start_with?('b') } # => {bar: 1, baz: 2} * h.keep_if { |key, value| key.start_with?('b') } # => {bar: 1, baz: 2}
* *
* Returns a new Enumerator if no block given: * With no block given, returns a new Enumerator.
* h = {foo: 0, bar: 1, baz: 2} *
* e = h.keep_if # => #<Enumerator: {foo: 0, bar: 1, baz: 2}:keep_if> * Related: see {Methods for Deleting}[rdoc-ref:Hash@Methods+for+Deleting].
* e.each { |key, value| key.start_with?('b') } # => {bar: 1, baz: 2}
*/ */
static VALUE static VALUE