diff options
author | Burdette Lamar <[email protected]> | 2025-03-23 10:09:08 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2025-03-23 11:09:08 -0400 |
commit | 12b2b577b7737ed4e81ca89b851fb429194c95fc (patch) | |
tree | 335f1495b95de0076841df200ad6e6909eb10e8e | |
parent | 383af53a56f7e4a490b891701f96f91ef31e0bef (diff) |
[DOC] Doc for Hash#transform_values!
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12944
Merged-By: peterzhu2118 <[email protected]>
-rw-r--r-- | hash.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -3435,18 +3435,24 @@ rb_hash_transform_values(VALUE hash) /* * call-seq: - * transform_values! {|value| ... } -> self + * transform_values! {|old_value| ... } -> self * transform_values! -> new_enumerator * - * Returns +self+, whose keys are unchanged, and whose values are determined by the given block. + * + * With a block given, changes the values of +self+ as determined by the block; + * returns +self+. + * + * For each entry +key+/+old_value+ in +self+, + * calls the block with +old_value+, + * captures its return value as +new_value+, + * and sets <tt>self[key] = new_value</tt>: + * * h = {foo: 0, bar: 1, baz: 2} * h.transform_values! {|value| value * 100} # => {foo: 0, bar: 100, baz: 200} * - * Returns a new Enumerator if no block given: - * h = {foo: 0, bar: 1, baz: 2} - * e = h.transform_values! # => #<Enumerator: {foo: 0, bar: 100, baz: 200}:transform_values!> - * h1 = e.each {|value| value * 100} - * h1 # => {foo: 0, bar: 100, baz: 200} + * With no block given, returns a new Enumerator. + * + * Related: see {Methods for Transforming Keys and Values}[rdoc-ref:Hash@Methods+for+Transforming+Keys+and+Values]. */ static VALUE rb_hash_transform_values_bang(VALUE hash) |