aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-14 23:09:55 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-14 23:09:55 +0000
commit13ef5fd4127517f43a9edebff906a023948df040 (patch)
tree3a8a1b6fc7844f44c9a8500e58b7522499698dc9 /array.c
parente18f247e7e5184d36f41d297c960ce03b9f4ef2d (diff)
downloadruby-13ef5fd4127517f43a9edebff906a023948df040.tar.gz
mention behavior of Array#join for nested arrays [ci skip]
The current documentation for Array#join does not mention the special treatment of nested arrays. It says: > Returns a string created by converting each element of the > array to a string, separated by the given separator. Expected behavior according to the docs would be: [ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-[1, 2, [:x, :y]]-b" # because of: [1, 2, [:x, :y]].to_s #=> "[1, 2, [:x, :y]]" Actual behavior: [ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-1-2-x-y-b" because join is applied recursively for nested arrays. The patch clarifies this behavior. (Also: small markup and grammar fix.) Patch by Marcus Stollsteimer <sto.mar@web.de> [ruby-talk:437238] [ruby-core:79079] [Bug #13130] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/array.c b/array.c
index 580d1838a1..a19e7bb710 100644
--- a/array.c
+++ b/array.c
@@ -2075,11 +2075,16 @@ rb_ary_join(VALUE ary, VALUE sep)
*
* Returns a string created by converting each element of the array to
* a string, separated by the given +separator+.
- * If the +separator+ is +nil+, it uses current $,.
- * If both the +separator+ and $, are nil, it uses empty string.
+ * If the +separator+ is +nil+, it uses current <code>$,</code>.
+ * If both the +separator+ and <code>$,</code> are +nil+,
+ * it uses an empty string.
*
* [ "a", "b", "c" ].join #=> "abc"
* [ "a", "b", "c" ].join("-") #=> "a-b-c"
+ *
+ * For nested arrays, join is applied recursively:
+ *
+ * [ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-1-2-x-y-b"
*/
static VALUE