Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is some special handling in the source to suppress the "duplicate argument name" error. The error message only appears in <code>shadowing_lvar_gen</code> inside <code>parse.y</code>, <a href="https://github.com/ruby/ruby/blob/ruby_1_9_3/parse.y#L8415" rel="noreferrer">the 1.9.3 version looks like this</a>:</p> <pre><code>static ID shadowing_lvar_gen(struct parser_params *parser, ID name) { if (idUScore == name) return name; /* ... */ </code></pre> <p>and <code>idUScore</code> is <a href="https://github.com/ruby/ruby/blob/ruby_1_9_3/id.c#L51" rel="noreferrer">defined in <code>id.c</code></a> like this:</p> <pre><code>REGISTER_SYMID(idUScore, "_"); </code></pre> <p>You'll see similar special handling in <a href="https://github.com/ruby/ruby/blob/ruby_1_9_3/parse.y#L9113" rel="noreferrer"><code>warn_unused_var</code></a>:</p> <pre><code>static void warn_unused_var(struct parser_params *parser, struct local_vars *local) { /* ... */ for (i = 0; i &lt; cnt; ++i) { if (!v[i] || (u[i] &amp; LVAR_USED)) continue; if (idUScore == v[i]) continue; rb_compile_warn(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i])); } } </code></pre> <p>You'll notice that the warning is suppressed on the second line of the <code>for</code> loop.</p> <p>The only special handling of <code>_</code> that I could find in the 1.9.3 source is above: the duplicate name error is suppressed and the unused variable warning is suppressed. Other than those two things, <code>_</code> is just a plain old variable like any other. I don't know of any documentation about the (minor) specialness of <code>_</code>.</p> <p>In Ruby 2.0, the <code>idUScore == v[i]</code> test in <a href="https://github.com/ruby/ruby/blob/ruby_2_0_0/parse.y#L9456" rel="noreferrer"><code>warn_unused_var</code></a> is replaced with a call to <code>is_private_local_id</code>:</p> <pre><code>if (is_private_local_id(v[i])) continue; rb_warn4S(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i])); </code></pre> <p>and <a href="https://github.com/ruby/ruby/blob/ruby_2_0_0/parse.y#L8606" rel="noreferrer"><code>is_private_local_id</code></a> suppresses warnings for variables that begin with <code>_</code>:</p> <pre><code>if (name == idUScore) return 1; /* ... */ return RSTRING_PTR(s)[0] == '_'; </code></pre> <p>rather than just <code>_</code> itself. So 2.0 loosens things up a bit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload