diff options
Diffstat (limited to 'doc/syntax/calling_methods.rdoc')
-rw-r--r-- | doc/syntax/calling_methods.rdoc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/syntax/calling_methods.rdoc b/doc/syntax/calling_methods.rdoc index a011144f71..79c0de59dc 100644 --- a/doc/syntax/calling_methods.rdoc +++ b/doc/syntax/calling_methods.rdoc @@ -322,3 +322,28 @@ avoid a warning. Unlike the splat operator described above the <code>&</code> operator has no commonly recognized name. +== Method Lookup + +When you send a message Ruby looks up the method that matches the name of the +message for the receiver. Methods are stored in classes and modules so method +lookup walks these, not the objects themselves. + +Here is the order of method lookup for the receiver's class or module +R+: + +* The prepended modules of +R+ in reverse order +* For a matching method in +R+ +* The included modules of +R+ in reverse order + +If +R+ is a class with a superclass, this is repeated with +R+'s superclass +until a method is found. + +Once a match is found method lookup stops. + +If no match is found this repeats from the beginning, but looking for ++method_missing+. The default +method_missing+ is BasicObject#method_missing +which raises a NameError when invoked. + +If refinements (an experimental feature) are active the method lookup changes. +See the {refinements documentation}[rdoc-ref:syntax/refinements.rdoc] for +details. + |