https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-05-10T07:12:24ZRuby Issue Tracking SystemRuby master - Feature #12360: More useful return values from bang methodshttps://bugs.ruby-lang.org/issues/12360?journal_id=585482016-05-10T07:12:24Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p><code>reject!</code> returns <code>nil</code> in case nothing was rejected at all. This is useful when a programmer wants to know if actual rejection happened or not, by using single <code>if</code> statement.<br>
Returning rejected elements can be handy on some scenarios, though. Maybe a separate method?</p> Ruby master - Feature #12360: More useful return values from bang methodshttps://bugs.ruby-lang.org/issues/12360?journal_id=585522016-05-10T07:50:22Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I think this proposal is to change the return value <em>if</em> actual rejection happened, but not the case nothing was rejected, and the result doesn't need to be <code>self</code> to know if it happened or not.</p>
<p>A drawback is a cost to create an array always even if it is not used.</p> Ruby master - Feature #12360: More useful return values from bang methodshttps://bugs.ruby-lang.org/issues/12360?journal_id=587782016-05-20T16:24:58Zdsferreira (Daniel Ferreira)
<ul></ul><p>The principle of least surprise puts my mind expecting as a result the updated array.<br>
A method to get both sides of the equation would make sense for me.<br>
Something like:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># Array#group</span>
<span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">].</span><span class="nf">group</span> <span class="p">{</span> <span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="n">i</span> <span class="o">></span> <span class="mi">0</span> <span class="p">}</span>
<span class="c1"># => [[2,4], [1,3]]</span>
</code></pre> Ruby master - Feature #12360: More useful return values from bang methodshttps://bugs.ruby-lang.org/issues/12360?journal_id=596542016-07-19T06:25:57Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>Rejected for several reasons:</p>
<ul>
<li>compatibility: the change will break many existing programs relying on the current behavior.</li>
<li>it decreases the performance of bang methods. since the primary reason for using bang method is efficiency, it is not acceptable.</li>
<li>the reason behind the current return value is to prevent method chaining of bang methods. since bang methods modifies the receivers, chaining them can easily confuse programmers.</li>
</ul>
<p>Matz.</p>