Project

General

Profile

Bug #13130

[DOC] Mention behavior of Array#join for nested arrays

Added by stomar (Marcus Stollsteimer) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
[ruby-core:79079]

Description

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.)


Files

doc_array_join.patch (806 Bytes) doc_array_join.patch stomar (Marcus Stollsteimer), 01/14/2017 08:38 PM

Associated revisions

Revision eeb36c5c
Added by normal over 2 years ago

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

Revision 57329
Added by normalperson (Eric Wong) over 2 years ago

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]

Revision 57329
Added by normal over 2 years ago

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]

Revision 57329
Added by normal over 2 years ago

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]

History

#1

Updated by Anonymous over 2 years ago

  • Status changed from Open to Closed

Applied in changeset r57329.


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]

Also available in: Atom PDF