[DOC] Tweaks for Array#join

This commit is contained in:
BurdetteLamar 2024-09-30 16:31:42 -05:00 committed by Peter Zhu
parent 467ebbebd9
commit e72e18b31d

17
array.c
View File

@ -2908,31 +2908,32 @@ rb_ary_join(VALUE ary, VALUE sep)
/* /*
* call-seq: * call-seq:
* array.join ->new_string
* array.join(separator = $,) -> new_string * array.join(separator = $,) -> new_string
* *
* Returns the new String formed by joining the array elements after conversion. * Returns the new string formed by joining the converted elements of +self+;
* For each element +element+: * for each element +element+:
* *
* - Uses <tt>element.to_s</tt> if +element+ is not a <tt>kind_of?(Array)</tt>. * - Converts recursively using <tt>element.join(separator)</tt>
* - Uses recursive <tt>element.join(separator)</tt> if +element+ is a <tt>kind_of?(Array)</tt>. * if +element+ is a <tt>kind_of?(Array)</tt>.
* - Otherwise, converts using <tt>element.to_s</tt>.
* *
* With no argument, joins using the output field separator, <tt>$,</tt>: * With no argument given, joins using the output field separator, <tt>$,</tt>:
* *
* a = [:foo, 'bar', 2] * a = [:foo, 'bar', 2]
* $, # => nil * $, # => nil
* a.join # => "foobar2" * a.join # => "foobar2"
* *
* With \string argument +separator+, joins using that separator: * With string argument +separator+ given, joins using that separator:
* *
* a = [:foo, 'bar', 2] * a = [:foo, 'bar', 2]
* a.join("\n") # => "foo\nbar\n2" * a.join("\n") # => "foo\nbar\n2"
* *
* Joins recursively for nested Arrays: * Joins recursively for nested arrays:
* *
* a = [:foo, [:bar, [:baz, :bat]]] * a = [:foo, [:bar, [:baz, :bat]]]
* a.join # => "foobarbazbat" * a.join # => "foobarbazbat"
* *
* Related: see {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting].
*/ */
static VALUE static VALUE
rb_ary_join_m(int argc, VALUE *argv, VALUE ary) rb_ary_join_m(int argc, VALUE *argv, VALUE ary)