[DOC] Tweaks for Hash#slice

This commit is contained in:
Burdette Lamar 2025-03-11 20:54:49 -05:00 committed by GitHub
parent 86eff8565b
commit 1b2cc9c2b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
Notes: git 2025-03-12 01:55:07 +00:00
Merged: https://github.com/ruby/ruby/pull/12907

Merged-By: peterzhu2118 <peter@peterzhu.ca>

10
hash.c
View file

@ -2646,11 +2646,13 @@ rb_hash_reject(VALUE hash)
* call-seq: * call-seq:
* slice(*keys) -> new_hash * slice(*keys) -> new_hash
* *
* Returns a new +Hash+ object containing the entries for the given +keys+: * Returns a new hash containing the entries from +self+ for the given +keys+;
* h = {foo: 0, bar: 1, baz: 2} * ignores any keys that are not found:
* h.slice(:baz, :foo) # => {baz: 2, foo: 0}
* *
* Any given +keys+ that are not found are ignored. * h = {foo: 0, bar: 1, baz: 2}
* h.slice(:baz, :foo, :nosuch) # => {baz: 2, foo: 0}
*
* Related: see {Methods for Deleting}[rdoc-ref:Hash@Methods+for+Deleting].
*/ */
static VALUE static VALUE