diff options
author | Burdette Lamar <[email protected]> | 2025-02-24 18:26:50 -0600 |
---|---|---|
committer | <[email protected]> | 2025-02-24 19:26:50 -0500 |
commit | 19f7961e46b2c5817b8eb27510c890d623ac14b3 () | |
tree | 33a9ef1ce86fa7171319e04517447e2d3f32f5b9 | |
parent | aa7b5e2df4e2acbc571998161ff4542b97b9d735 (diff) |
[DOC] Tweaks for Hash#flatten
Notes: Merged: https://.com/ruby/ruby/pull/12792 Merged-By: peterzhu2118 <[email protected]>
-rw-r--r-- | hash.c | 61 |
1 files changed, 32 insertions, 29 deletions
@@ -4285,33 +4285,38 @@ flatten_i(VALUE key, VALUE val, VALUE ary) /* * call-seq: - * flatten -> new_array - * flatten(level) -> new_array * - * Returns a new Array object that is a 1-dimensional flattening of +self+. * - * --- * - * By default, nested Arrays are not flattened: - * h = {foo: 0, bar: [:bat, 3], baz: 2} - * h.flatten # => [:foo, 0, :bar, [:bat, 3], :baz, 2] - * - * Takes the depth of recursive flattening from Integer argument +level+: - * h = {foo: 0, bar: [:bat, [:baz, [:bat, ]]]} - * h.flatten(1) # => [:foo, 0, :bar, [:bat, [:baz, [:bat]]]] - * h.flatten(2) # => [:foo, 0, :bar, :bat, [:baz, [:bat]]] - * h.flatten(3) # => [:foo, 0, :bar, :bat, :baz, [:bat]] - * h.flatten(4) # => [:foo, 0, :bar, :bat, :baz, :bat] - * - * When +level+ is negative, flattens all nested Arrays: - * h = {foo: 0, bar: [:bat, [:baz, [:bat, ]]]} - * h.flatten(-1) # => [:foo, 0, :bar, :bat, :baz, :bat] - * h.flatten(-2) # => [:foo, 0, :bar, :bat, :baz, :bat] - * - * When +level+ is zero, returns the equivalent of #to_a : - * h = {foo: 0, bar: [:bat, 3], baz: 2} - * h.flatten(0) # => [[:foo, 0], [:bar, [:bat, 3]], [:baz, 2]] - * h.flatten(0) == h.to_a # => true */ static VALUE @@ -7076,7 +7081,6 @@ static const rb_data_type_t env_data_type = { * - {Iterating}[rdoc-ref:Hash@Methods+for+Iterating] * - {Converting}[rdoc-ref:Hash@Methods+for+Converting] * - {Transforming Keys and Values}[rdoc-ref:Hash@Methods+for+Transforming+Keys+and+Values] - * - {And more....}[rdoc-ref:Hash@Other+Methods] * * Class +Hash+ also includes methods from module Enumerable. * @@ -7164,6 +7168,7 @@ static const rb_data_type_t env_data_type = { * * ==== Methods for Converting * * - #inspect (aliased as #to_s): Returns a new String containing the hash entries. * - #to_a: Returns a new array of 2-element arrays; * each nested array contains a key-value pair from +self+. @@ -7174,15 +7179,13 @@ static const rb_data_type_t env_data_type = { * * ==== Methods for Transforming Keys and Values * * - #transform_keys: Returns a copy of +self+ with modified keys. * - #transform_keys!: Modifies keys in +self+ * - #transform_values: Returns a copy of +self+ with modified values. * - #transform_values!: Modifies values in +self+. * - * ==== Other Methods - * - #flatten: Returns an array that is a 1-dimensional flattening of +self+. - * - #invert: Returns a hash with the each key-value pair inverted. - * */ void |