Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually, auto-completion does work for <code>.</code>. The completion options are found by calling <code>#methods</code> on the object. You can see this for yourself by overriding <code>Object.methods</code>:</p> <pre><code>&gt;&gt; def Object.methods; ["foo", "bar"]; end =&gt; nil &gt;&gt; Object.[TAB] Object.foo Object.bar &gt;&gt; Object. </code></pre> <p>Note that this only works when the expression to the left of the <code>.</code> is a literal. Otherwise, getting the object to call <code>#methods</code> on would involve evaluating the left-hand side, which could have side-effects. You can see this for yourself as well:</p> <pre><code>[continuing from above...] &gt;&gt; def Object.baz; Object; end =&gt; nil &gt;&gt; Object.baz.[TAB] Display all 1022 possibilities? (y or n) </code></pre> <p>We add a method <code>#baz</code> to <code>Object</code> which returns <code>Object</code> itself. Then we auto-complete to get the methods we can call on <code>Object.baz</code>. If IRB called <code>Object.baz.methods</code>, it would get the same thing as <code>Object.methods</code>. Instead, IRB has 1022 suggestions. I'm not sure where they come from, but it's clearly a generic list which isn't actually based on context.</p> <p>The <code>::</code> operator is (also) used for getting a module's constants, while <code>.</code> is not. That's why <code>HTTP</code> will show up in the completion for <code>Net::</code>, but not for <code>Net.</code>. <code>Net.HTTP</code> isn't correct, but <code>Net::HTTP</code> is.</p>
 

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