https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-11-20T03:10:55ZRuby Issue Tracking SystemRuby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331142012-11-20T03:10:55Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> changed from <i>mame (Yusuke Endoh)</i> to <i>matz (Yukihiro Matsumoto)</i></li><li><strong>Target version</strong> set to <i>2.6</i></li></ul><p>In principle, I have no right to judge a feature request.<br>
Please ask matz.</p>
<p>My personal opinion: the method name will matter.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331222012-11-20T03:37:34Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>My personal opinion: the method name will matter.</p>
</blockquote>
<p>I'd even say that <code>embed</code> is wrong.</p>
<p>I would like to know of a good example of use case. I often succumb to the temptation of writing more complex code to avoid creating a local var, but that doesn't always make for better code.</p>
<p>The example given in the github PR was:</p>
<pre><code>[ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total => x.count, :data => x}}...
</code></pre>
<p>I feel the following is clearer:</p>
<pre><code>odd_nbs = [ 1, 2, 3, 4].select{|x| x.odd?}
{:total => odd_nbs.count, :data => odd_nbs}...
</code></pre>
<p>Until I see a good use case (and a good method name is found), I'm -1 for this.</p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331242012-11-20T04:29:33Znathan.f77 (Nathan Broadbent)nathan.f77@gmail.com
<ul></ul><blockquote>
<p>I'd even say that <code>embed</code> is wrong.</p>
<p>I would like to know of a good example of use case. I often succumb to the<br>
temptation of writing more complex code to avoid creating a local var, but<br>
that doesn't always make for better code.</p>
<p>The example given in the github PR was:</p>
<pre><code>[ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total => x.count, :data
</code></pre>
<p>=> x}}...</p>
<p>I feel the following is clearer:</p>
<pre><code>odd_nbs = [ 1, 2, 3, 4].select{|x| x.odd?}
{:total => odd_nbs.count, :data => odd_nbs}...
</code></pre>
</blockquote>
<p>How about <code>infix</code>? I think this method could be a useful addition, even if<br>
it's rarely used. Also, the example usage might be clearer with a better<br>
block argument:</p>
<pre><code> [ 1, 2, 3, 4].select{|x| x.odd?}.infix{|odd_nbs| {:total => odd_nbs.count,
</code></pre>
<p>:data => odd_nbs}}</p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331262012-11-20T05:53:17Ztrans (Thomas Sawyer)
<ul></ul><p>Is this #ergo? Also see <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Object#yield_self (Closed)" href="https://redmine.ruby-lang.org/issues/6721">#6721</a> and <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: public #self (Closed)" href="https://redmine.ruby-lang.org/issues/6373">#6373</a>.</p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331272012-11-20T06:07:15Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>=begin<br>
I am against those names (not the feature).</p>
<p>: embed<br>
the term 'embed' has different impression.</p>
<p>: infix<br>
'infix' reminds me 'infix operators'.</p>
<p>: ergo<br>
Latin? I am strongly against introducing non-popular non-English names as standard methods.</p>
<p>Basically it's too much for a method that can be defined in 3 lines in your code.<br>
Come back if your think of another name.</p>
<p>Matz.</p>
<p>=end</p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=331332012-11-20T07:09:26Ztrans (Thomas Sawyer)
<ul></ul><p>=begin<br>
I thought about a few terms that might work in both cases, i.e. the so called "embed" case of this issue and the "identity" case of <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: public #self (Closed)" href="https://redmine.ruby-lang.org/issues/6373">#6373</a>. All of the obvious plays on the term "self" didn't fair too well. So I took a step back and asked what it was the method was really asking for. I answered, "a reference to the object itself". So then, it occurred to me, what about #reference?</p>
<p>a.group_by(&:reference)</p>
<p>a.reference{ |r| ... }</p>
<p>=end</p> Ruby master - Feature #7388: Object#embedhttps://redmine.ruby-lang.org/issues/7388?journal_id=605632016-09-20T00:55:15Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/12760">Feature #12760</a>: Optional block argument for `itself`</i> added</li></ul>