Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782021-02-17T18:07:16ZRuby Issue Tracking System
Redmine Ruby master - Feature #17640 (Rejected): allow // for commentshttps://bugs.ruby-lang.org/issues/176402021-02-17T18:07:16Zfoonlyboy (Eike Dierks)
<ul>
<li>ruby uses '#' for comments (from the sh heritage)</li>
<li>js and css use '//' for comments (from the C++ heritage)</li>
</ul>
<p>I'd like to discuss,<br>
to allow '//' in ruby code for comments</p>
<p>Motivation:</p>
<ul>
<li>writing comments is good</li>
<li>it's cumbersome to adapt the comments to the language currrently active</li>
</ul>
<p>Impact:</p>
<p>Please check:</p>
<ul>
<li>'//' is not a token in ruby?</li>
<li>there is no way to make a legal expression involving '//'?</li>
<li>oops ... the empty regexp literal is //</li>
</ul>
<p>This is where the things get complicated<br>
in terms of full backwards compatibility.</p>
<p>But I think that can be done.<br>
'//i' is a legal expression,<br>
while '// i' never was?</p>
<p>Anyways, I just want to put this on for a first discussion.</p> Ruby master - Feature #17170 (Feedback): Numeric.zero, Numeric.onehttps://bugs.ruby-lang.org/issues/171702020-09-15T19:07:11Zfoonlyboy (Eike Dierks)
<p>Hi at the ruby team,</p>
<p>I'd like to suggest to enhance <code>Numeric</code> to provide two new class methods, which shall be: <code>zero</code> and <code>one</code>.</p>
<ul>
<li>
<code>Integer.zero</code> shall be equal to <code>Integer(0)</code>
</li>
<li>
<code>Float.zero</code> shall be equal to <code>Float(0)</code>
</li>
<li>
<code>BigDecimal.zero</code> shall be equal to <code>BigDecimal(0)</code>
</li>
<li>
<code>Complex.zero</code> shall be equal to <code>Complex(0)</code>
</li>
</ul>
<p>Likewise for <code>one</code>, you get the idea.</p>
<p><code>Numeric</code> already provides <code>#zero?</code>, so <code>Numeric.zero.zero?</code> shall always be <code>true</code>.</p>
<p>I expect this to make code more explicit. And it would save a pair of braces.<br>
(Don't laugh--This really got me here.)</p>
<hr>
<p>Maybe you already considered that for 3.0, which would be a late addition.</p>
<p>Ruby shines in teaching mathematics. You know, we have zero and one there.</p>
<p>I use ruby in the financial realm. For me, it's important to write <code>BigDecimal.zero</code>.</p>
<hr>
<p>I expect that the new API should not break existing code. We could try it with Rails first. Let's ask them.</p>
<p>It would be nice to have that in [Rails] 3.</p>
<p>~eike</p> Ruby master - Feature #15829 (Rejected): Object#then_if(condition){}https://bugs.ruby-lang.org/issues/158292019-05-05T18:26:18Zfoonlyboy (Eike Dierks)
<p>I'd like to propose some sugar to Object#then</p>
<p>There should be <code>Object#then_if(condition, &block)</code></p>
<p>The block should only be applied when the condition is true,<br>
otherwise the object should be returned without applying the block.</p>
<p>Rationale:</p>
<p>I frequently use <code>Object#then</code> with Rails to extend queries like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">foo</span><span class="p">.</span><span class="nf">then</span> <span class="p">{</span><span class="o">|</span><span class="n">query</span><span class="o">|</span>
<span class="k">if</span><span class="p">(</span><span class="n">condition</span><span class="p">)</span>
<span class="n">query</span><span class="p">.</span><span class="nf">where</span><span class="p">(</span><span class="n">zip</span><span class="ss">:zap</span><span class="p">)</span>
<span class="k">else</span>
<span class="n">query</span>
<span class="k">end</span>
<span class="p">}</span>
</code></pre>
<p>by using the proposed <code>Object#then_if</code> the example could be simplified to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">foo</span><span class="p">.</span><span class="nf">then_if</span><span class="p">(</span><span class="n">condition</span><span class="p">)</span> <span class="p">{</span><span class="o">|</span><span class="n">query</span><span class="o">|</span>
<span class="n">query</span><span class="p">.</span><span class="nf">where</span><span class="p">(</span><span class="n">zip</span><span class="ss">:zap</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>
<p>I believe that this also applies to a lot of other use cases,<br>
i.e. only applying some transformation if some condition is true,<br>
but otherwise leaving the result untouched.</p> Ruby master - Feature #15668 (Open): stdlib: Date - Time should return the difference in dayshttps://bugs.ruby-lang.org/issues/156682019-03-15T01:41:01Zfoonlyboy (Eike Dierks)
<p>Hi at the ruby/stdlib,</p>
<p>Computing with times and dates is very complicated.<br>
There are so many pitfalls lurking there.</p>
<p>I stumbled about a seemingly simple computation,<br>
involving Date and Time</p>
<p>try:<br>
Date.today - Time.now<br>
=> TypeError: expected numeric</p>
<p>while my naively expected result can done by:<br>
Date.today - Time.now.to_date<br>
=> (0/1)</p>
<p>There must be a whole lot of good reasons why Date - Time is not allowed.</p>
<p>I'd like to suggest:</p>
<ul>
<li>improve the error message</li>
<li>improve the documentation of #-</li>
</ul>
<p>For the error message:<br>
TypeError: expected numeric<br>
should be improved to:<br>
Date - Time is not allowed</p>
<p>The documentation of Date should state why this is so problematic.</p>
<p>You might even want to add a principal documentation,<br>
about the handling of Date and Time in ruby</p>
<hr>
<p>you can't tune a fish</p> Ruby master - Misc #15474 (Rejected): Running Rails with jithttps://bugs.ruby-lang.org/issues/154742018-12-27T21:58:09Zfoonlyboy (Eike Dierks)
<p>I have installed ruby-2.6.0<br>
I want to try to run my rails app with the jit.</p>
<p>How can this be done?<br>
I should try env RUBY_OPTS='--jit'<br>
Is this the way the go?</p>
<p>The jit ist experimental, but promising,<br>
so we need to try it wherever we can.</p>
<p>there needs to be a clear documentation,<br>
how to enable or disable jit</p>
<p>I'd like to enable jit by default,<br>
when running 2.6.0</p>
<p>running 2.5.3 with --jit gives:<br>
/opt/local/bin/ruby --jit -e 'puts "hello world"'<br>
/opt/local/bin/ruby: invalid option --jit (-h will show valid options) (RuntimeError)</p>
<p>I'd like to suggest a new env: RUBY_JIT<br>
which should only be respected by ruby >= 2.6.0</p>
<p>~eike</p> Ruby master - Misc #15418 (Open): Date.parse('2018')https://bugs.ruby-lang.org/issues/154182018-12-15T18:43:56Zfoonlyboy (Eike Dierks)
<p>Date.parse('2018')<br>
ArgumentError: invalid date</p>
<p>I did expect that to return the same as:<br>
Date.parse('2018-1-1')<br>
=> Mon, 01 Jan 2018</p>
<p>working with dates and times is really weird and complicated,<br>
so it makes sense to be strict with parsing.</p>
<p>I watched this one:<br>
<a href="https://www.youtube.com/watch?v=-5wpm-gesOY" class="external">https://www.youtube.com/watch?v=-5wpm-gesOY</a><br>
He's really coming up with some some crazy test cases.</p>
<p>In ruby this is split between Time and DateTime,<br>
some in the core, some in in the standard lib.</p>
<hr>
<p>Im looking forward for the new version,<br>
let's freeze the strings!</p>
<p>~eike</p> Ruby master - Bug #15210 (Closed): UTF-8 BOM should be removed from String in internal representa...https://bugs.ruby-lang.org/issues/152102018-10-06T18:47:17Zfoonlyboy (Eike Dierks)
<p>Hi everyone working on the ruby trunk,</p>
<p>I encountered a problem with a BOM (Byte Order Mark) at the front of UTF-8 string data.</p>
<p>We import some CSV from paypal.<br>
They now include a BOM in front of their UTF-8 encoded CSV data.<br>
This BOM is making some troubles.</p>
<p>I believe this to be a bug in how byte data is converted to the ruby internal String representation.</p>
<p>There is a workaround, but this needs to be documented:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">IO</span><span class="p">.</span><span class="nf">read</span><span class="p">(</span><span class="n">mode</span><span class="ss">:'r:BOM|UTF-8'</span><span class="p">)</span>
</code></pre>
<hr>
<p>But I'm asking for to improve the UTF-BOM handling:</p>
<ul>
<li>The BOM is only used for transfer encoding at the byte stream level.</li>
<li>The BOM MUST NOT be part of the String in internal representation.</li>
</ul>
<hr>
<p>BTW: stdlib::CSV chokes on the BOM</p>
<p>I'd like to add some code for a workaround:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">String</span>
<span class="c1"># delete UTF Byte Order Mark from string</span>
<span class="c1"># returns self (even if no bom was found, contrary to delete_prefix!)</span>
<span class="c1"># NOTE: use with care: better remove the bom when reading the file</span>
<span class="k">def</span> <span class="nf">delete_bom!</span>
<span class="k">raise</span> <span class="s1">'encoding is not UTF-8'</span> <span class="k">unless</span> <span class="nb">self</span><span class="p">.</span><span class="nf">encoding</span> <span class="o">==</span> <span class="no">Encoding</span><span class="o">::</span><span class="no">UTF_8</span>
<span class="n">delete_prefix!</span><span class="p">(</span><span class="s2">"</span><span class="se">\xEF\xBB\xBF</span><span class="s2">"</span><span class="p">)</span>
<span class="k">return</span> <span class="nb">self</span>
<span class="k">end</span>
<span class="c1"># returns a copy of string with UTF Byte Order Mark deleted from string</span>
<span class="k">def</span> <span class="nf">delete_bom</span>
<span class="nb">dup</span><span class="p">.</span><span class="nf">delete_bom!</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<hr>
<p>~eike</p> Ruby master - Feature #15149 (Open): extend string format to nil safehttps://bugs.ruby-lang.org/issues/151492018-09-22T21:57:14Zfoonlyboy (Eike Dierks)
<p>I'd like to suggest a new modifier for the string format<br>
(aka the printf-style format string)</p>
<a name="Examples"></a>
<h2 >Examples<a href="#Examples" class="wiki-anchor">¶</a></h2>
<a name="Current"></a>
<h3 >Current<a href="#Current" class="wiki-anchor">¶</a></h3>
<pre><code>'%s' % nil => ''
'%d' % nil => Exception: TypeError: can't convert nil into Integer
</code></pre>
<a name="Suggestion"></a>
<h3 >Suggestion<a href="#Suggestion" class="wiki-anchor">¶</a></h3>
<pre><code>'%&s' % nil => 'nil'
'%&d' % nil => 'nil'
</code></pre>
<a name="Explanation"></a>
<h2 >Explanation<a href="#Explanation" class="wiki-anchor">¶</a></h2>
<p>I suggest to introduce a new modifier for the format strings.<br>
(in the examples above I used the ampersand char: <strong>&</strong>)</p>
<p>That modifier should change the behaviour of string formatting in two ways:</p>
<ul>
<li>accept nil as an argument <em>for all conversion formats</em>
</li>
<li>display explicit <strong>'nil'</strong> when <strong>nil</strong> is given as an argument</li>
</ul>
<a name="Rationale"></a>
<h2 >Rationale<a href="#Rationale" class="wiki-anchor">¶</a></h2>
<p>This feature would be most helpful for log messages and printf style debugging</p>
<ul>
<li>
<p>currently only the %s format accepts nil, but returns an empty string.</p>
</li>
<li>
<p>all other formats raise on nil</p>
</li>
<li>
<p>when displaying strings, nil args show up indiscernible from empty strings</p>
</li>
<li>
<p>when displaying anything else (like %d, %f etc) things just break</p>
</li>
</ul>
<a name="Compatibility"></a>
<h2 >Compatibility<a href="#Compatibility" class="wiki-anchor">¶</a></h2>
<p>I believe that this new feature would be fully compatible with any existing code.<br>
Up to now the ampersand was not allowed as a modifier and results in an Exception:</p>
<pre><code>'%&d' % nil => ArgumentError: malformed format string - %&
</code></pre>
<p>As far as I know, the ampersand has not been used in other variations of printf, yet.</p>
<a name="Design"></a>
<h2 >Design<a href="#Design" class="wiki-anchor">¶</a></h2>
<p>I suggest to use the <strong>&</strong> (ampersand) because that would be in line with the ruby nil safe operator.</p>
<p>I opt for <em>explicitly</em> showing 'nil' for nil args (instead of the empty string)</p>