Question

When experimenting in irb, I frequently call upon the tab completion to show a list of available methods for the target objects.

Could the function that outputs this list of method names be one that is defined in either Object or BasicObject, or is it a function implemented by irb itself?

I assumed this list would be the formatted result of an Array returned by a call to public_methods, the but the lists seem to differ somewhat:

1.9.3-p448 :026 > 1.
Display all 115 possibilities? (y or n)
                              1.divmod                      1.inspect                     
1.numerator                   1.respond_to?                 1.to_enum
1.__id__                      1.downto                      1.instance_eval
1.object_id                   1.respond_to_missing?         1.to_f                   
1.__send__                    1.dup                         1.instance_exec
1.odd?                        1.round                       1.to_i               
1.abs                         1.enum_for                    1.instance_of?                                         

1.9.3-p448 :027 > 1.public_methods.sort
 => [:!, :!=, :!~, :%, :&, :*, :**, :+, :+@, :-, :-@, :/, :<, :<<, :<=, :<=>, :==, :===,
     :=~, :>, :>=, :>>, :[], :^, :__id__, :__send__, :abs, :abs2, :angle, :arg,
     :as_null_object,     :between?, :ceil, :chr, :class, :clone, :coerce, :conj,
     :conjugate, :define_singleton_method,     :denominator, :display, :div

None of the operator methods are displayed in the tab list, for example. so, where does the tab list come from?

Was it helpful?

Solution

Completion in IRb is provided by the irb/completion standard library, which is unfortunately undocumented. You can find the source for the case you are interested in here: https://GitHub.Com/Ruby/Ruby/blob/trunk/lib/irb/completion.rb#L149-195

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top