Skip to content

Commit 4129973

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for Hash#fetch_values
1 parent 7ef9110 commit 4129973

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

hash.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,19 +2727,23 @@ rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
27272727
* fetch_values(*keys) -> new_array
27282728
* fetch_values(*keys) {|key| ... } -> new_array
27292729
*
2730-
* Returns a new Array containing the values associated with the given keys *keys:
2730+
* When all given +keys+ are found,
2731+
* returns a new array containing the values associated with the given +keys+:
2732+
*
27312733
* h = {foo: 0, bar: 1, baz: 2}
27322734
* h.fetch_values(:baz, :foo) # => [2, 0]
27332735
*
2734-
* Returns a new empty Array if no arguments given.
2736+
* When any given +keys+ are not found and a block is given,
2737+
* calls the block with each unfound key and uses the block's return value
2738+
* as the value for that key:
27352739
*
2736-
* When a block is given, calls the block with each missing key,
2737-
* treating the block's return value as the value for that key:
2738-
* h = {foo: 0, bar: 1, baz: 2}
2739-
* values = h.fetch_values(:bar, :foo, :bad, :bam) {|key| key.to_s}
2740-
* values # => [1, 0, "bad", "bam"]
2740+
* h.fetch_values(:bar, :foo, :bad, :bam) {|key| key.to_s}
2741+
* # => [1, 0, "bad", "bam"]
27412742
*
2742-
* When no block is given, raises an exception if any given key is not found.
2743+
* When any given +keys+ are not found and no block is given,
2744+
* raises KeyError.
2745+
*
2746+
* Related: see {Methods for Fetching}[rdoc-ref:Hash@Methods+for+Fetching].
27432747
*/
27442748

27452749
static VALUE

0 commit comments

Comments
 (0)