Actually, auto-completion does work for .
. The completion options are found by calling #methods
on the object. You can see this for yourself by overriding Object.methods
:
>> def Object.methods; ["foo", "bar"]; end
=> nil
>> Object.[TAB]
Object.foo Object.bar
>> Object.
Note that this only works when the expression to the left of the .
is a literal. Otherwise, getting the object to call #methods
on would involve evaluating the left-hand side, which could have side-effects. You can see this for yourself as well:
[continuing from above...]
>> def Object.baz; Object; end
=> nil
>> Object.baz.[TAB]
Display all 1022 possibilities? (y or n)
We add a method #baz
to Object
which returns Object
itself. Then we auto-complete to get the methods we can call on Object.baz
. If IRB called Object.baz.methods
, it would get the same thing as Object.methods
. 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.
The ::
operator is (also) used for getting a module's constants, while .
is not. That's why HTTP
will show up in the completion for Net::
, but not for Net.
. Net.HTTP
isn't correct, but Net::HTTP
is.