https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112015-06-16T22:17:35ZRuby Issue Tracking SystemRuby master - Bug #10928: optparse Switch#summarize code doesn't reflect its documentationhttps://redmine.ruby-lang.org/issues/10928?journal_id=529632015-06-16T22:17:35Zdavydov_anton (Anton Davydov)antondavydov.o@gmail.com
<ul></ul><p>Hello,</p>
<blockquote>
<p>However, the actual method definition line shows otherwise, namely an Array.</p>
</blockquote>
<p>In documentations says that <code>sdone</code> and <code>ldone</code> options take keyed hash. It's mean that this options take array with hash keys.</p>
<blockquote>
<p>The <code>OptionParser#summarize</code> command does actually invoke it with Hashes as arguments (line 566): <code>visit(:summarize, {}, {}, width, max, indent, &blk)</code>.</p>
</blockquote>
<p>It's different methods. In first case it's <code>Switch#summarize</code> and in second case it's <code>OptionParser#summarize</code>.</p> Ruby master - Bug #10928: optparse Switch#summarize code doesn't reflect its documentationhttps://redmine.ruby-lang.org/issues/10928?journal_id=791852019-07-07T20:57:21Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7883">optparse-switch-summarize.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7883/optparse-switch-summarize.patch">optparse-switch-summarize.patch</a> added</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul><p>I agree that this is a bug and it should be fixed. You can trigger it by calling <code>OptionParser::Switch#summarize</code> without arguments:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'optparse'</span>
<span class="n">o</span> <span class="o">=</span> <span class="no">OptionParser</span><span class="p">.</span><span class="nf">new</span>
<span class="n">o</span><span class="p">.</span><span class="nf">on</span><span class="p">(</span><span class="s1">'-c'</span><span class="p">){}</span>
<span class="n">o</span><span class="p">.</span><span class="nf">instance_variable_get</span><span class="p">(</span><span class="ss">:@stack</span><span class="p">)[</span><span class="mi">2</span><span class="p">].</span><span class="nf">instance_variable_get</span><span class="p">(</span><span class="ss">:@short</span><span class="p">).</span><span class="nf">values</span><span class="p">.</span><span class="nf">first</span><span class="p">.</span><span class="nf">summarize</span><span class="p">{}</span>
<span class="c1"># TypeError (no implicit conversion of String into Integer)</span>
</code></pre>
<p>Attached is a patch that fixes the issue.</p> Ruby master - Bug #10928: optparse Switch#summarize code doesn't reflect its documentationhttps://redmine.ruby-lang.org/issues/10928?journal_id=792002019-07-08T01:46:11Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Thank you, I've missed it.<br>
Commit it please.</p> Ruby master - Bug #10928: optparse Switch#summarize code doesn't reflect its documentationhttps://redmine.ruby-lang.org/issues/10928?journal_id=792032019-07-08T01:59:05Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Fix default argument values for OptParse::Switch#summarize The documentation describes these arg..." href="https://redmine.ruby-lang.org/projects/ruby-master/repository/git/revisions/3fcffceafd2bce7186851bf4899484c545a9ace8">git|3fcffceafd2bce7186851bf4899484c545a9ace8</a>.</p>
<hr>
<p>Fix default argument values for OptParse::Switch#summarize</p>
<p>The documentation describes these arguments being hashes, and the method<br>
is called with hashes, so a hash default makes more sense.</p>
<p>The method would fail previously if called without arguments and @short<br>
or @long contained a non-integer value.</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: optparse Switch#summarize code doesn't reflect its documentation (Closed)" href="https://redmine.ruby-lang.org/issues/10928">#10928</a>]</p>