mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Tweaks for Hash#select! (#12904)
This commit is contained in:
parent
a5f29213dc
commit
b52f789520
Notes:
git
2025-05-14 12:41:59 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
1 changed files with 10 additions and 7 deletions
17
hash.c
17
hash.c
|
@ -2809,16 +2809,19 @@ rb_hash_select(VALUE hash)
|
|||
* select! {|key, value| ... } -> self or nil
|
||||
* select! -> new_enumerator
|
||||
*
|
||||
* Returns +self+, whose entries are those for which the block returns a truthy value:
|
||||
* h = {foo: 0, bar: 1, baz: 2}
|
||||
* h.select! {|key, value| value < 2 } => {foo: 0, bar: 1}
|
||||
* With a block given, calls the block with each entry's key and value;
|
||||
* removes from +self+ each entry for which the block returns +false+ or +nil+.
|
||||
*
|
||||
* Returns +nil+ if no entries were removed.
|
||||
* Returns +self+ if any entries were removed, +nil+ otherwise:
|
||||
*
|
||||
* Returns a new Enumerator if no block given:
|
||||
* h = {foo: 0, bar: 1, baz: 2}
|
||||
* e = h.select! # => #<Enumerator: {foo: 0, bar: 1, baz: 2}:select!>
|
||||
* e.each { |key, value| value < 2 } # => {foo: 0, bar: 1}
|
||||
* h.select! {|key, value| value < 2 } # => {foo: 0, bar: 1}
|
||||
* h.select! {|key, value| value < 2 } # => nil
|
||||
*
|
||||
*
|
||||
* With no block given, returns a new Enumerator.
|
||||
*
|
||||
* Related: see {Methods for Deleting}[rdoc-ref:Hash@Methods+for+Deleting].
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue