https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-09-22T03:58:23ZRuby Issue Tracking SystemRuby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=668282017-09-22T03:58:23Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><blockquote>
<p>This causes SO MANY ISSUES!</p>
</blockquote>
<p>If you build up a <code>String</code> such as:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">x</span> <span class="o">=</span> <span class="mi">42</span>
<span class="n">y</span> <span class="o">=</span> <span class="c1"># String here</span>
</code></pre>
<p>Then you can use:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">y</span> <span class="o">=</span> <span class="s2">"The answer to everything is </span><span class="si">#{</span><span class="n">x</span><span class="si">}</span><span class="s2">"</span>
</code></pre>
<p>For global variables this is even shorter, though global variables<br>
are not very pretty:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="vg">$x</span> <span class="o">=</span> <span class="mi">42</span> <span class="c1"># => 42</span>
<span class="n">y</span> <span class="o">=</span> <span class="s2">"yo there </span><span class="si">#$x</span><span class="s2">"</span> <span class="c1"># => "yo there 42"</span>
</code></pre>
<p>In the above, you do not have to manually use <code>.to_s</code>.</p>
<blockquote>
<p>Instead of CRASHING</p>
</blockquote>
<p>It does not "crash". It raises a specific error.</p>
<p>I think it was once explained why the behaviour is the way it is; I<br>
may not correctly remember though so I don't speculate. (I was thinking<br>
of error detection in code being harder.)</p>
<p>The recommended way is to use <code>""</code> with <code>#{}</code> for variables, or any of<br>
the alternative variants (the ones with <code>%</code> come to mind but I think<br>
<code>#{}</code> is easier to understand than the <code>%</code> variants; just that you get<br>
more control via <code>%</code> string formatting e. g. if you need some leading<br>
0 to some float value or something, in one go).</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=668302017-09-22T04:40:49Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Anon92929 (Anon Ymous) wrote:</p>
<blockquote>
<p>This causes SO MANY ISSUES! Instead of CRASHING, why doesn't it just apply the <code>.to_s</code> operator in this case???</p>
</blockquote>
<p>What is "this case"?</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=669332017-09-26T11:34:34Zsbhatore (Siddharth Bhatore)
<ul></ul><p>I don't understand the problem clearly. Can you explain it ?</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=708632018-03-08T05:24:13Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Rejected</i></li></ul><p>Seems satisfied.</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=708902018-03-08T07:40:25ZAnon92929 (Anon Ymous)
<ul></ul><p><a href="https://bugs.ruby-lang.org/issues/14589" class="external">https://bugs.ruby-lang.org/issues/14589</a></p>
<p>Not satisfied.</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=708932018-03-08T08:14:21ZAnon92929 (Anon Ymous)
<ul></ul><blockquote>
<p>It does not "crash". It raises a specific error.</p>
</blockquote>
<p>Halting executing while raising an error is called 'crashing' to most people.</p> Ruby master - Bug #13929: TypeError: no implicit conversion of XXXX into stringhttps://bugs.ruby-lang.org/issues/13929?journal_id=713422018-03-31T10:39:06Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-1 status-6 priority-4 priority-default closed" href="/issues/14589">Bug #14589</a>: "No implicit conversion of XXX to string" asserion should be handled with an explicit string conversion, and it should be a warning not an assertion</i> added</li></ul>