https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112016-11-14T04:39:10ZRuby Issue Tracking SystemRuby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=614792016-11-14T04:39:10Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>In Ruby, all operators have to be written at the end of the line to make it possible to distinguish between complete statements (with a missing semicolon) and continuations.</p>
<p>The only exception is the '.' operator, which is allowed to be on the next line to make method chaining look better, as follows:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">array</span><span class="p">.</span><span class="nf">map</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">select</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">reject</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">group</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">sort</span> <span class="o">...</span>
</code></pre>
<p>What do you think is special about the ternary operator?</p> Ruby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=614842016-11-14T09:30:20Zmutantkeyboard (Antonio Nesic)
<ul><li><strong>File</strong> <a href="/attachments/6242">Screen Shot 2016-11-14 at 10.24.39.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6242/Screen%20Shot%202016-11-14%20at%2010.24.39.png">Screen Shot 2016-11-14 at 10.24.39.png</a> added</li><li><strong>ruby -v</strong> set to <i>2.3.1</i></li></ul><p>Martin Dürst wrote:</p>
<blockquote>
<p>In Ruby, all operators have to be written at the end of the line to make it possible to distinguish between complete statements (with a missing semicolon) and continuations.</p>
<p>The only exception is the '.' operator, which is allowed to be on the next line to make method chaining look better, as follows:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">array</span><span class="p">.</span><span class="nf">map</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">select</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">reject</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">group</span> <span class="o">...</span>
<span class="p">.</span><span class="nf">sort</span> <span class="o">...</span>
</code></pre>
<p>What do you think is special about the ternary operator?</p>
</blockquote>
<p>I think that this is what he meant. If he uses IRB, then the syntax error comes up like:</p>
<pre><code>SyntaxError: (irb):14: syntax error, unexpected '?', expecting ')'
from /Users/antonionesic/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
</code></pre>
<p>But I have to agree. This is a SyntaxError, and not a bug.<br>
Ticket should be closed.</p> Ruby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=615072016-11-15T06:16:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/61507/diff?detail_id=43092">diff</a>)</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>It is not a bug, and easy to extend the parser to allow that syntax, but doesn't look nice to me.</p> Ruby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=625662017-01-19T08:14:26Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><a href="https://github.com/ruby/ruby/compare/trunk...nobu:feature/12929-ternary" class="external">https://github.com/ruby/ruby/compare/trunk...nobu:feature/12929-ternary</a></p> Ruby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=625672017-01-19T08:17:04Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I don't think it's worth modifying the syntax. If you want to write complex conditional code, use if-statement.</p>
<p>Matz.</p> Ruby master - Feature #12929: ternary should look ahead w/in a block (and not care about newlines)https://redmine.ruby-lang.org/issues/12929?journal_id=943602021-10-27T16:47:25Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul>