Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-01-05T23:31:08ZRuby Issue Tracking System
Redmine Ruby master - Feature #13108 (Open): [Doc Request] Explicitly document Range#sumhttps://bugs.ruby-lang.org/issues/131082017-01-05T23:31:08Zsnood1205 (Eli Sadoff)snood1205@gmail.com
<p>While <code>Range#sum</code> exists because it implements <code>Enumerable#sum</code>, it is not noted how it works. While it does provide a hint that it is not an alias to <code>inject(:+)</code>, it is not explained that <code>(a..b).sum</code> implements <code>(b-a+1)*(a+b)/2</code> which is <code>O((log n)^2)</code> instead of <code>(a..b).inject(:+)</code> which is <code>O(n log n)</code>. It might be worth while either explicitly document <code>Range#sum</code> or at least documenting in <code>Enumerable#sum</code> that <code>Range#sum</code> has this behavior because the current documentation is not particularly descriptive and hides, what I think of, as quite a brilliant feature of 2.4.0.</p> Ruby master - Bug #13099 (Closed): Binding#irb does not work outside of irbhttps://bugs.ruby-lang.org/issues/130992017-01-03T23:36:14Zsnood1205 (Eli Sadoff)snood1205@gmail.com
<p>I had read that one of the new features of 2.4.0 is that <code>Binding#irb</code> is now a method, so I decided to test this out in a program I was working on. Here is the program</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Test</span>
<span class="nb">attr_accessor</span> <span class="ss">:x</span><span class="p">,</span> <span class="ss">:y</span><span class="p">,</span> <span class="ss">:z</span>
<span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="vi">@x</span> <span class="o">=</span> <span class="n">x</span>
<span class="vi">@y</span> <span class="o">=</span> <span class="n">y</span>
<span class="nb">binding</span><span class="p">.</span><span class="nf">irb</span>
<span class="vi">@z</span> <span class="o">=</span> <span class="n">z</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">a</span> <span class="o">=</span> <span class="no">Test</span><span class="p">.</span><span class="nf">new</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>
</code></pre>
<p>And the error that I got is</p>
<pre><code>binding_test.rb:6:in `initialize': undefined method `irb' for #<Binding:0x007f8562025078> (NoMethodError)
from binding_test.rb:11:in `new'
from binding_test.rb:11:in `<main>'
</code></pre>
<p>So, I thought that maybe it was an issue with running it in a constructor, so I tried the simpler invocation</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">binding</span><span class="p">.</span><span class="nf">irb</span>
</code></pre>
<p>but I had a problem with that as well, with a very similar error message</p>
<pre><code>bind.rb:1:in `<main>': undefined method `irb' for #<Binding:0x007ff34984e880> (NoMethodError)
</code></pre>