https://bugs.ruby-lang.org/
https://bugs.ruby-lang.org/favicon.ico?1711330511
2021-08-21T08:28:21Z
Ruby Issue Tracking System
Ruby master - Misc #18125: A strange behavior when same name variable/method coexist issue.
https://bugs.ruby-lang.org/issues/18125?journal_id=93450
2021-08-21T08:28:21Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul></ul><p>It is excepted because of variable hoisting.</p>
<p>Same reason why <code>foo = 1 unless foo</code> works.</p>
Ruby master - Misc #18125: A strange behavior when same name variable/method coexist issue.
https://bugs.ruby-lang.org/issues/18125?journal_id=93451
2021-08-21T09:31:28Z
matz (Yukihiro Matsumoto)
matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Local variables are defined when they appear in assignments, thus</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="n">deploy_to</span> <span class="o">=</span> <span class="s2">"</span><span class="si">#{</span><span class="n">deploy_to</span><span class="si">}</span><span class="s2"> new place"</span>
<span class="c1"># ^ assignment ^local variable</span>
</code></pre>
<p>To avoid ambiguity, use parenthesis.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="n">deploy_to</span> <span class="o">=</span> <span class="s2">"</span><span class="si">#{</span><span class="n">deploy_to</span><span class="p">()</span><span class="si">}</span><span class="s2"> new place"</span>
</code></pre>
<p>Matz.</p>