ruby-changes:45256
From: normal <ko1@a...>
Date: Sun, 15 Jan 2017 08:10:00 +0900 (JST)
Subject: [ruby-changes:45256] normal:r57329 (trunk): mention behavior of Array#join for nested arrays [ci skip]
normal 2017-01-15 08:09:55 +0900 (Sun, 15 Jan 2017) New Revision: 57329 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57329 Log: 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@w...> [ruby-talk:437238] [ruby-core:79079] [Bug #13130] Modified files: trunk/array.c Index: array.c =================================================================== --- array.c (revision 57328) +++ array.c (revision 57329) @@ -2075,11 +2075,16 @@ rb_ary_join(VALUE ary, VALUE sep) https://github.com/ruby/ruby/blob/trunk/array.c#L2075 * * 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/