Project

General

Profile

Actions

Feature #12333

closed

Updated by duerst (Martin Dürst) about 9 years ago

I think this can occasionally be helpful, and shouldn't be too difficult to implement. Can you provide a ?

Updated by spinute (Satoru Horie) about 9 years ago

I will try to write a for it!

Updated by spinute (Satoru Horie) about 9 years ago

I have written a .

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 9 years ago

I wrote another refined for a problem stated in a previous post.

It behaves like below

ar = [1]
ar.concat(ar, ar) #=> [1,1,1]

str = "ab"
str.concat(str, str) #=> "ababab"

Updated by sawa (Tsuyoshi Sawada) about 9 years ago

Satoru, thank you for the .

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 9 years ago

  • Related to : accept multiple arguments at Array#delete added

Updated by matz (Yukihiro Matsumoto) about 9 years ago

Approved. I want to

ar = [1]
ar.concat(ar, ar)

to result [1,1,1].

Matz.

Updated by spinute (Satoru Horie) about 9 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 9 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 by Satoru Horie. [Feature ]
  • string.c (rb_str_concat_multi, rb_str_prepend_multi): ditto.

Updated by stomar (Marcus Stollsteimer) over 8 years ago

  • Related to : [DOC] Restore docs for String#<< added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0