https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112016-05-02T01:45:02ZRuby Issue Tracking SystemRuby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=584212016-05-02T01:45:02Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>I think this can occasionally be helpful, and shouldn't be too difficult to implement. Can you provide a patch?</p> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=584262016-05-02T03:25:38Zspinute (Satoru Horie)
<ul></ul><p>I will try to write a patch for it!</p> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=584462016-05-03T07:15:04Zspinute (Satoru Horie)
<ul><li><strong>File</strong> <a href="/attachments/5941">multi_concat_prepend.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/5941/multi_concat_prepend.patch">multi_concat_prepend.patch</a> added</li></ul><p>I have written a patch.</p>
<p>And, there are some points to ask</p>
<ul>
<li>
<p>What is the appropriate behavior when calling concat/prepend without argument?</p>
</li>
<li>
<p>The code attached now returns just self</p>
</li>
<li>
<p>What should happen when writing ar.concat(ar, ar)?</p>
</li>
<li>
<p>ar = [1]; ar.concat(ar, ar) #=> [1,1,1]? or [1,1,1,1]?</p>
</li>
<li>
<p>ar << ar << ar returns [1,1,1,1], of course because this is just a sequence of binary operations</p>
</li>
<li>
<p>However, I feel "ar.concat(ar, ar)" saying "append present content of the array twice to the array", meaning [1,1,1]</p>
</li>
<li>
<p>The code attached returns [1,1,1,1], for now, just for the simplicity of implementation</p>
</li>
</ul> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=584472016-05-03T08:08:36Zspinute (Satoru Horie)
<ul><li><strong>File</strong> <a href="/attachments/5942">fixed_multi_concat_prepend.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/5942/fixed_multi_concat_prepend.patch">fixed_multi_concat_prepend.patch</a> added</li></ul><p>I wrote another patch refined for a problem stated in a previous post.</p>
<p>It behaves like below</p>
<pre><code>ar = [1]
ar.concat(ar, ar) #=> [1,1,1]
str = "ab"
str.concat(str, str) #=> "ababab"
</code></pre> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=584482016-05-03T08:23:44Zsawa (Tsuyoshi Sawada)
<ul></ul><p>Satoru, thank you for the patch.</p>
<p>And you are making good points with the questions you raised.</p>
<blockquote>
<ul>
<li>What is the appropriate behavior when calling concat/prepend without argument?</li>
<li>The code attached now returns just self</li>
</ul>
</blockquote>
<p>I agree with this behavior. I think this would be the most natural.</p>
<blockquote>
<ul>
<li>What should happen when writing ar.concat(ar, ar)?</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>ar = [1]; ar.concat(ar, ar) #=> [1,1,1]? or [1,1,1,1]?</li>
<li>ar << ar << ar returns [1,1,1,1], of course because this is just a sequence of binary operations</li>
</ul>
</blockquote>
<p>This is more logical (in some sense), but counter-intuitive.</p>
<blockquote>
<ul>
<li>However, I feel "ar.concat(ar, ar)" saying "append present content of the array twice to the array", meaning [1,1,1]</li>
</ul>
</blockquote>
<p>This is more intuitive, but may be less logical.</p>
<p>I have preference with the second option, but am not completely sure. Maybe other people might have different opinions.</p> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=588792016-05-28T04:40:44Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/12247">Feature #12247</a>: accept multiple arguments at Array#delete</i> added</li></ul> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=591602016-06-13T06:46:50Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Approved. I want to</p>
<pre><code>ar = [1]
ar.concat(ar, ar)
</code></pre>
<p>to result <code>[1,1,1]</code>.</p>
<p>Matz.</p> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=592882016-06-20T15:32:21Zspinute (Satoru Horie)
<ul><li><strong>File</strong> <a href="/attachments/6032">multi_concat_prepend.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6032/multi_concat_prepend.patch">multi_concat_prepend.patch</a> added</li></ul><p>I added some test cases for Array#concat, String#concat and String#prepend and refined error handling.<br>
Also, I fixed my code to conform to convention.<br>
Any feedback is welcome!</p> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=603032016-08-27T01:26:23Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset r56021.</p>
<hr>
<p>multiple arguments</p>
<ul>
<li>array.c (rb_ary_concat_multi): take multiple arguments. based<br>
on the patch by Satoru Horie. [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: `String#concat`, `Array#concat`, `String#prepend` to take multiple arguments (Closed)" href="https://redmine.ruby-lang.org/issues/12333">#12333</a>]</li>
<li>string.c (rb_str_concat_multi, rb_str_prepend_multi): ditto.</li>
</ul> Ruby master - Feature #12333: `String#concat`, `Array#concat`, `String#prepend` to take multiple argumentshttps://redmine.ruby-lang.org/issues/12333?journal_id=632972017-03-02T10:23:38Zstomar (Marcus Stollsteimer)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/13268">Bug #13268</a>: [DOC] Restore docs for String#<<</i> added</li></ul>