https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112017-10-19T21:39:07ZRuby Issue Tracking SystemRuby master - Feature #14033: Add String#appendhttps://redmine.ruby-lang.org/issues/14033?journal_id=673652017-10-19T21:39:07Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I +1 agree with Stefan for symmetry. :)</p>
<p>However had, I may be biased since I discussed in favour of the<br>
Array-methods .prepend() and .append() so it may be best if others<br>
can comment here too, to avoid "mono-view bias". :)</p> Ruby master - Feature #14033: Add String#appendhttps://redmine.ruby-lang.org/issues/14033?journal_id=673662017-10-20T00:22:57Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>I am opposed to this alias as proposed.</p>
<ol>
<li>
<p><code><<</code> is known to be "dangerous", but other "safe" concatenation operations exist for String (e.g. <code>+</code>). I would expect that a <em>new</em> word-based name for the dangerous operation would end with "<code>!</code>".</p>
</li>
<li>
<p><code><<</code> (and <code>concat</code>) casts integers as codepoints. <code>prepend</code> requires that <em>all</em> arguments are Stringy (c.f. <code>+</code>). A method named to look like <code>prepend</code>, but that behaves like <code>concat</code>, is confusing.</p>
</li>
<li>
<p><code><<</code> only accepts a single argument, but <code>concat</code> accepts many, so this alias would introduce confusion about which method (concat vs. append) has what arity.</p>
</li>
</ol>
<p>If the proposal were about adding <a href="https://github.com/phluid61/mug/blob/master/lib/mug/affix.rb" class="external">new functionality</a> I think it would be worth considering, but I'm against adding a new name for the sake of it.</p> Ruby master - Feature #14033: Add String#appendhttps://redmine.ruby-lang.org/issues/14033?journal_id=673822017-10-20T06:43:12Zsos4nt (Stefan Schüßler)mail@stefanschuessler.de
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>1 [...] I would expect that a new word-based name for the dangerous operation would end with "!".</p>
</blockquote>
<p>That contradicts <code>Array#append</code> / <code>Array#prepend</code>. And since <code>String#prepend</code> also modifies the receiver, I would expect <code>String#append</code> to work in a similar way.</p>
<p>(Off topic but IMO, <code>String#concat</code> is the one that should return a new string, just like the documentation for <code>String#+</code> says: <em>"Concatenation—Returns a new String containing other_str concatenated to str."</em> But it's probably a bit late to fix that.)</p>
<blockquote>
<p>2 [...] A method named to look like prepend, but that behaves like concat, is confusing.</p>
</blockquote>
<p>Good point. I'm fine with string-only arguments. <code>append</code> would simply invoke <code>rb_str_append</code> then (is that a coincidence?).</p>
<blockquote>
<p>3 [...] this alias would introduce confusion about which method (concat vs. append) has what arity.</p>
</blockquote>
<p>It should of course work (arity-wise) like <code>Array#append</code>, i.e. accept multiple argument. I should have said "concat", not "<<" in the question's title, or better yet not call it an alias in the first place.</p>
<hr>
<p>To avoid any further confusion: I'm proposing a <em>new</em> method <code>String#append</code> with the following signature:</p>
<blockquote>
<a name="appendother_str1-other_str2-str"></a>
<h3 >append(other_str1, other_str2,...) → str<a href="#appendother_str1-other_str2-str" class="wiki-anchor">¶</a></h3>
<p>Append—Append the given strings to <em>str</em>.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span> <span class="o">=</span> <span class="s2">"hello "</span>
<span class="n">a</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="s2">"world"</span><span class="p">,</span> <span class="s2">"!"</span><span class="p">)</span> <span class="c1">#=> "hello world!"</span>
<span class="n">a</span> <span class="c1">#=> "hello world!"</span>
</code></pre>
<p>See also <em>#concat</em>.</p>
</blockquote> Ruby master - Feature #14033: Add String#appendhttps://redmine.ruby-lang.org/issues/14033?journal_id=673832017-10-20T06:52:44Zsos4nt (Stefan Schüßler)mail@stefanschuessler.de
<ul><li><strong>Subject</strong> changed from <i>Alias String#<< as String#append</i> to <i>Add String#append</i></li></ul> Ruby master - Feature #14033: Add String#appendhttps://redmine.ruby-lang.org/issues/14033?journal_id=733622018-08-08T03:01:45Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>I would like to propose to extend this method to be binary safe.</p>
<p>If the destination string uses <code>Encoding::BINARY</code>, the append operation should be a memcpy which doesn't affect the receiver's encoding.</p>