https://bugs.ruby-lang.org/
https://bugs.ruby-lang.org/favicon.ico?1711330511
2021-11-13T19:34:19Z
Ruby Issue Tracking System
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=94631
2021-11-13T19:34:19Z
zverok (Victor Shepelev)
zverok.offline@gmail.com
<ul></ul><pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">puts</span> <span class="s2">"</span><span class="si">#{</span><span class="s1">'font-bold'</span> <span class="k">if</span> <span class="kp">true</span><span class="si">}</span><span class="s2">"</span>
<span class="c1"># => font-bold</span>
</code></pre>
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=94632
2021-11-13T19:42:32Z
dorianmariefr (Dorian MariƩ)
<ul></ul><p>Thanks, I still think the <code>root? ? "font-bold"</code> reads better than <code>"font-bold" if root?</code> though</p>
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=94633
2021-11-13T20:36:39Z
zverok (Victor Shepelev)
zverok.offline@gmail.com
<ul></ul><p>Well, obviously that's a matter of personal taste, but for a one-branch <code>if</code> the postfix form seems to read naturally ("this item will have class "font-bold" if it is root).</p>
<p>So it might be that <code>cond ? result</code> reads better for you because you invented it starting to think from <code>cond ? result : else</code> (which, should we say, is quite esoteric on itself, we just got used to it)</p>
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=94634
2021-11-14T00:42:09Z
sawa (Tsuyoshi Sawada)
<ul></ul><p><code>"font-bold" if root?</code> reads much better than <code>root? ? "font-bold"</code>.</p>
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=95677
2021-12-28T14:48:28Z
joelb (Joel Blum)
<ul></ul><p>If we adopt this syntax it might be worthwhile to consider JS new colaescing operator which does the same thing, maybe it's better to keep the syntax similar to JS. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator" class="external">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator</a>.</p>
<p>So basically just</p>
<p>a ?? b</p>
Ruby master - Feature #18332: a ? b
https://bugs.ruby-lang.org/issues/18332?journal_id=95694
2021-12-29T04:38:43Z
nobu (Nobuyoshi Nakada)
nobu@ruby-lang.org
<ul></ul><p><code>??</code> is a character literal.<br>
As omitting the <code>:</code> and after makes the syntax value conflicting of course, I don't think this is acceptable.</p>