Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-07-10T02:37:11ZRuby Issue Tracking System
Redmine Ruby master - Feature #17022 (Third Party's Issue): Addition of method Kernel#Datehttps://bugs.ruby-lang.org/issues/170222020-07-10T02:37:11Zamericodls (Americo Duarte)
<p>What if we have a method <code>Kernel#Date</code> that delegates to <code>Date.parse</code>? Dates could be written in a more natural way, right?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Date</span><span class="p">(</span><span class="s2">"2020-01-13"</span><span class="p">)</span> <span class="o">-</span> <span class="no">Date</span><span class="p">(</span><span class="s2">"2019-01-13"</span><span class="p">)</span>
</code></pre>
<p>Capitalized methods are defined on the <code>Kernel</code> module to facilitate construction of basic types:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Kernel</span><span class="p">.</span><span class="nf">methods</span><span class="p">.</span><span class="nf">grep</span><span class="p">(</span><span class="sr">/^[A-Z].*/</span><span class="p">)</span>
<span class="c1">#=> [:Rational, :Complex, :URI, :Integer, :Float, :String, :Array, :Hash, :Pathname]</span>
</code></pre>
<p>Method <code>BigDecimal</code> is added when the corresponding library is required:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'bigdecimal'</span>
<span class="no">Kernel</span><span class="p">.</span><span class="nf">methods</span><span class="p">.</span><span class="nf">grep</span><span class="p">(</span><span class="sr">/^[A-Z].*/</span><span class="p">)</span>
<span class="c1">#=> [:Rational, :Complex, :BigDecimal, :URI, :Integer, :Float, :String, :Array, :Hash, :Pathname]</span>
</code></pre>
<p>The proposal is to do the same; when we do <code>require 'date'</code>, a method <code>Kernel#Date</code> should be added.</p> Ruby master - Bug #13592 (Closed): Enumerable#reduce with symbol does not respect method visibilityhttps://bugs.ruby-lang.org/issues/135922017-05-23T14:37:33Zamericodls (Americo Duarte)
<p>When use reduce with symbol, I expect the symbol is called in object but respecting the method visibility.</p>
<p>Example with source code written in a file.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Fixnum</span><span class="p">.</span><span class="nf">instance_eval</span> <span class="k">do</span>
<span class="kp">private</span> <span class="p">:</span><span class="o">+</span>
<span class="k">end</span>
<span class="nb">p</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">].</span><span class="nf">reduce</span><span class="p">(:</span><span class="o">+</span><span class="p">)</span>
</code></pre>
<p>The behavior in IRB is different.</p>
<pre><code>irb(main):001:0> [1,2,3].reduce(:+)
=> 6
irb(main):002:0> Fixnum.instance_eval do
irb(main):003:1* private :+
irb(main):004:1> end
=> Fixnum
irb(main):005:0>
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/input-method.rb:154:in `gets': private method `+' called for 4:Fixnum (NoMethodError)
</code></pre>
<p>Now, I am confused. Those behaviors are expected? In doc this is not clear.</p> Ruby master - Feature #13581 (Closed): Syntax sugar for method referencehttps://bugs.ruby-lang.org/issues/135812017-05-19T12:44:35Zamericodls (Americo Duarte)
<p>Some another programming languages (even Java, in version 8) has a cool way to refer a method as a reference.</p>
<p>I wrote some examples here: <a href="https://gist.github.com/americodls/20981b2864d166eee8d231904303f24b" class="external">https://gist.github.com/americodls/20981b2864d166eee8d231904303f24b</a></p>
<p>I miss this thing in ruby.</p>
<p>I would thinking if is possible some like this:</p>
<pre><code>roots = [1, 4, 9].map &Math.method(:sqrt)
</code></pre>
<p>Could be like this:</p>
<pre><code>roots = [1, 4, 9].map Math->method
</code></pre>
<p>What do you guys thinking about it?</p>