https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-02-29T18:15:18ZRuby Issue Tracking SystemRuby master - Bug #12128: Strings in `ARGV` are frozenhttps://bugs.ruby-lang.org/issues/12128?journal_id=572102016-02-29T18:15:18Zsawa (Tsuyoshi Sawada)
<ul></ul><p>Sorry, I found that it is indeed a feature that they are frozen. Please reject this.</p> Ruby master - Bug #12128: Strings in `ARGV` are frozenhttps://bugs.ruby-lang.org/issues/12128?journal_id=572122016-02-29T19:35:48Z0x0dea (D.E. Akers)0x0dea+redmine@gmail.com
<ul></ul><p>Be advised that you can say <code>ARGV.map!(&:+@)</code> if you really want to modify the elements in-place, but that's probably not the best idea.</p> Ruby master - Bug #12128: Strings in `ARGV` are frozenhttps://bugs.ruby-lang.org/issues/12128?journal_id=572152016-02-29T20:33:05Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I believe that this is actually how ruby may have behaved before the transition into frozen strings<br>
already; at the least, I seem to distinctly remember that, if I write a method such as:</p>
<hr>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'pp'</span>
<span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="no">ARGV</span><span class="p">)</span>
<span class="n">pp</span> <span class="n">i</span>
<span class="k">end</span>
<span class="n">foo</span>
</code></pre>
<hr>
<p>Then the input was considered "tainted", which I assume may refer to external input in<br>
general, and the Strings that are in <code>ARGV</code> were always frozen.</p>
<p>So I think one always had to write code that would handle this situation properly. This<br>
does not say anything about your proposal by the way, I have no particular pro or contra<br>
opinion whatsoever, but I think that this was how ruby always treated <code>ARGV</code>. (I would usually<br>
pass this through a setter method that will do the proper sanitizing for me; that is, how<br>
I would respond to user input in general. It may be interesting to know how <code>OptionParser</code><br>
/ optparse handles commandline input, I personally tend to be very lazy and am often fine<br>
for small classes to just check against an internal <code>menu()</code> method, which would select<br>
the behaviour for the given class, such as <code>--disable-colours</code> and such to control colour<br>
output, and so on and so forth.)</p>
<p>So to come to your question:</p>
<blockquote>
<p><strong>Is it a feature that they are always frozen?</strong></p>
</blockquote>
<p>I think that there was an old explanation for this, which probably is still valid today<br>
since <code>ARGV</code> always were frozen, or perhaps at the least since when I was using ruby (I<br>
have no idea about ruby 1.0 :D )</p> Ruby master - Bug #12128: Strings in `ARGV` are frozenhttps://bugs.ruby-lang.org/issues/12128?journal_id=572222016-03-01T02:09:39Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul>