Feature #12333
closed`String#concat`, `Array#concat`, `String#prepend` to take multiple arguments
Description
Files
Updated by duerst (Martin Dürst) about 10 years ago
I think this can occasionally be helpful, and shouldn't be too difficult to implement. Can you provide a patch?
Updated by spinute (Satoru Horie) about 10 years ago
I will try to write a patch for it!
Updated by spinute (Satoru Horie) about 10 years ago
I have written a patch.
And, there are some points to ask
-
What is the appropriate behavior when calling concat/prepend without argument?
-
The code attached now returns just self
-
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
-
However, I feel "ar.concat(ar, ar)" saying "append present content of the array twice to the array", meaning [1,1,1]
-
The code attached returns [1,1,1,1], for now, just for the simplicity of implementation
Updated by spinute (Satoru Horie) about 10 years ago
Updated by sawa (Tsuyoshi Sawada) about 10 years ago
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.
Updated by hsbt (Hiroshi SHIBATA) about 10 years ago
- Related to Feature #12247: accept multiple arguments at Array#delete added
Updated by matz (Yukihiro Matsumoto) about 10 years ago
Updated by spinute (Satoru Horie) about 10 years ago
I added some test cases for Array#concat, String#concat and String#prepend and refined error handling.
Also, I fixed my code to conform to convention.
Any feedback is welcome!
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Status changed from Open to Closed
Applied in changeset r56021.
multiple arguments
- array.c (rb_ary_concat_multi): take multiple arguments. based
on the patch by Satoru Horie. [Feature #12333] - string.c (rb_str_concat_multi, rb_str_prepend_multi): ditto.
Updated by stomar (Marcus Stollsteimer) over 9 years ago
- Related to Bug #13268: [DOC] Restore docs for String#<< added