https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112018-11-07T00:33:42ZRuby Issue Tracking SystemRuby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=747822018-11-07T00:33:42Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I think one possible question in regards to the suggestion here is whether the above method may be useful<br>
on its own, even without a shorthand syntax for Hash. (This is really just a question; I personally am<br>
not having any strong pro/con opinion.)</p>
<p>I also understand that using a method is different compared to the other two proposals. For example,</p>
<pre><code>{ a }
{ a: a}
</code></pre>
<p>and</p>
<pre><code>{x, y}
{x: x, y: y}
</code></pre>
<p>is different to:</p>
<pre><code>meth = 42
p expand(:meth) # => {:meth=>42}
</code></pre>
<p>So using a method is different to the other two proposals (in the two older<br>
issue request, by Ignatius and Shugo Maeda). Perhaps one or more use cases<br>
could be described for a new method to be useful even without the hash<br>
shorthand notation? I can not think of a good one right now but perhaps others<br>
have some ideas.</p> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=747842018-11-07T04:22:32Zosyo (manga osyo)
<ul></ul><p>Thanks for comment, shevegen.<br>
<code>Kernel.#expand</code> can be used as follows.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="ss">:a</span><span class="p">,</span> <span class="ss">:b</span><span class="p">,</span> <span class="ss">:meth</span><span class="p">]</span>
<span class="c1"># expand(:a, :b, :meth)</span>
<span class="n">expand</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">)</span>
<span class="c1"># => {:a=>1, :b=>2, :meth=>"meth"}</span>
<span class="c1"># ???</span>
<span class="p">{</span> <span class="o">*</span><span class="n">names</span> <span class="p">}</span>
</code></pre> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=749202018-11-19T02:20:17Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Interesting feature, but I don't think the name <code>Kernel#expand</code> is acceptable.<br>
Maybe an instance method of <code>Binding</code>?<br>
And I think it should raise a <code>NameError</code> instead of a <code>NoMethodError</code> on invalid names.</p> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=749222018-11-19T02:43:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>And, what do you expect for keywords, e.g., <code>__FILE__</code>, <code>__LINE__</code>, <code>self</code>, <code>super</code>, and etc?</p> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=750072018-11-21T13:32:22Zosyo (manga osyo)
<ul></ul><p>Thanks nobu :)</p>
<blockquote>
<p>Interesting feature, but I don't think the name Kernel#expand is acceptable.</p>
</blockquote>
<p>Yes, I looking for a more good name.<br>
Are there any good names?</p>
<blockquote>
<p>Maybe an instance method of Binding?</p>
</blockquote>
<p>Yes..., but <code>binding.expand(:a, :b, :c)</code> is long...<br>
<code>Kernel.#expand</code> got the idea from <code>Kernel.#local_variables</code>.</p>
<blockquote>
<p>And I think it should raise a NameError instead of a NoMethodError on invalid names.</p>
</blockquote>
<p>OK, I try :)</p>
<blockquote>
<p>And, what do you expect for keywords, e.g., <strong>FILE</strong>, <strong>LINE</strong>, self, super, and etc?</p>
</blockquote>
<p>Yes, I think it is necessary to discuss what to "expand".<br>
This is a simple implementation with methods and local variables</p> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=750932018-11-22T22:31:44Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/15236">Feature #15236</a>: add support for hash shorthand</i> added</li></ul> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=750942018-11-22T22:36:23Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I am against the idea for some reasons:</p>
<ul>
<li>I don't think <code>expand</code> is the right name for the behavior</li>
<li>meta-programming is too much for this half-baked substitute for <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: add support for hash shorthand (Rejected)" href="https://bugs.ruby-lang.org/issues/15236">#15236</a></li>
</ul>
<p>Regarding <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: add support for hash shorthand (Rejected)" href="https://bugs.ruby-lang.org/issues/15236">#15236</a>, we are waiting for the time when our recognition changed to accept the JS behavior. Currently, we (at least me) recognize <code>{a,b,c}</code> as a literal for a set, not a shorthand for <code>{a:a,b:b,c:c}</code>. I am neutral. I don't want Ruby to follow every JS behavior.</p>
<p>Matz.</p> Ruby master - Feature #15286: Proposal: Add Kernel.#expand(*args)https://bugs.ruby-lang.org/issues/15286?journal_id=751342018-11-24T08:21:20Zosyo (manga osyo)
<ul></ul><p>OK, Thank you, matz :)</p>