Issue #12333 has been updated by Tsuyoshi Sawada.


Satoru, thank you for the patch.

And you are making good points with the questions you raised.

> * What is the appropriate behavior when calling concat/prepend without argument?
>  * The code attached now returns just self

I agree with this behavior. I think this would be the most natural.

> * What should happen when writing ar.concat(ar, ar)?

>  * ar = [1]; ar.concat(ar, ar) #=> [1,1,1]? or [1,1,1,1]?
>  * ar << ar << ar returns [1,1,1,1], of course because this is just a sequence of binary operations

This is more logical (in some sense), but counter-intuitive.

>  * However, I feel "ar.concat(ar, ar)" saying "append present content of the array twice to the array", meaning [1,1,1]

This is more intuitive, but may be less logical.

I have preference with the second option, but am not completely sure. Maybe other people might have different opinions.

----------------------------------------
Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple arguments
https://bugs.ruby-lang.org/issues/12333#change-58448

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I would like `String#concat`, `Array#concat`, `String#prepend` to take multiple arguments

~~~ruby
s = ""
s.concat("a", "b", "c")
a.prepend("A", "B", "C")
s # => "ABCabc"

a = []
a.concat(["a"], ["b", "c"])
a # => ["a", "b", "c"]
~~~

---Files--------------------------------
multi_concat_prepend.patch (2.94 KB)
fixed_multi_concat_prepend.patch (3.14 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>