https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112018-03-23T08:41:07ZRuby Issue Tracking SystemRuby master - Feature #14625: yield_self accepts an argument, calling to_prochttps://redmine.ruby-lang.org/issues/14625?journal_id=711692018-03-23T08:41:07Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><p>Question 1. How is this (proposed):</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">result</span> <span class="o">=</span> <span class="n">collection</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter1</span><span class="p">)</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter2</span><span class="p">)</span>
</code></pre>
<p>better than this (already works):</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">result</span> <span class="o">=</span> <span class="n">collection</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&</span><span class="nb">method</span><span class="p">(</span><span class="ss">:filter1</span><span class="p">))</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&</span><span class="nb">method</span><span class="p">(</span><span class="ss">:filter2</span><span class="p">))</span>
</code></pre>
<p>?</p>
<p>Question 2: what about all other methods that accepts blocks of code? If the syntax shown above is available for <code>#yield_self</code>, shouldn't it become available for <code>#each</code>, <code>#map</code> and everything else?..</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">collection</span><span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter1</span><span class="p">)</span>
<span class="n">collection</span><span class="p">.</span><span class="nf">map</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter1</span><span class="p">)</span>
</code></pre>
<p>I believe that the real improvement of "passing the method" situation would be the <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Syntax sugar for method reference (Closed)" href="https://redmine.ruby-lang.org/issues/13581">#13581</a>, so you can write something like:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">collection</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&.</span><span class="ss">:filter1</span><span class="p">)</span>
<span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&.</span><span class="ss">:filter2</span><span class="p">)</span>
</code></pre> Ruby master - Feature #14625: yield_self accepts an argument, calling to_prochttps://redmine.ruby-lang.org/issues/14625?journal_id=711762018-03-23T19:48:05Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I can't answer all questions zverok posed but in regards to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter2</span><span class="p">)</span>
</code></pre>
<p>versus</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&</span><span class="nb">method</span><span class="p">(</span><span class="ss">:filter1</span><span class="p">))</span>
</code></pre>
<p>The first variant is cleaner IMO.</p>
<p>As for <code>(&.:filter1)</code> I don't really like that suggestion and<br>
I think it should not be connected to irohiroki's issue<br>
request here since he did not suggest it. :)</p>
<p>While I agree that it would be great if we could have a<br>
way to also pass in arguments rather than just invoke<br>
method calls vie e. g. <code>array.map(&:strip)</code> alone, I am<br>
not convinced that <strong><code>&.:</code></strong> should be the way to go. It<br>
looks very perlish and the dots are not so easily<br>
distinguishable (we use <code>::</code> for "namespace" separators<br>
currently and <code>.</code> for method calls).</p>
<p>So on that, I think we should keep towards the suggestion<br>
itself given by irohiroki. And I think he meant it only<br>
for <code>yield_self</code>, not for any other method. Of course one<br>
can argue that symmetry should exist for all methods<br>
(though I am not sure as to why, other than thinking<br>
that symmetry is more important even if it may be useless<br>
for some methods).</p> Ruby master - Feature #14625: yield_self accepts an argument, calling to_prochttps://redmine.ruby-lang.org/issues/14625?journal_id=713312018-03-30T06:49:20Zirohiroki (Hiroki Yoshioka)
<ul></ul><p>zverok,</p>
<p>Answer 1.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="nb">method</span> <span class="ss">:filter1</span><span class="p">)</span>
</code></pre>
<p>is shorter than</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">.</span><span class="nf">yield_self</span><span class="p">(</span><span class="o">&</span><span class="nb">method</span><span class="p">(</span><span class="ss">:filter1</span><span class="p">))</span>
</code></pre>
<p>and doesn't have nested parens.</p>
<p>Answer 2: I don't really know about other methods, but there is a method named <code>Enumerable#inject</code> and actually it accepts a symbol as an argument that is special among methods having a block. What I mean is that there can be a special method, although I'm not sure it's really nice.</p>
<p>Regarding <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Syntax sugar for method reference (Closed)" href="https://redmine.ruby-lang.org/issues/13581">#13581</a>, it can help me but anyway it's still open right now.</p> Ruby master - Feature #14625: yield_self accepts an argument, calling to_prochttps://redmine.ruby-lang.org/issues/14625?journal_id=713322018-03-30T06:52:43Zirohiroki (Hiroki Yoshioka)
<ul></ul><p>shevegen,</p>
<p>That's what I meant to say. Thank you.</p>