ruby-changes:26876
From: drbrain <ko1@a...>
Date: Thu, 24 Jan 2013 16:54:54 +0900 (JST)
Subject: [ruby-changes:26876] drbrain:r38928 (trunk): * doc/syntax/calling_methods.rdoc: Added a Method Lookup section.
drbrain 2013-01-24 16:54:45 +0900 (Thu, 24 Jan 2013) New Revision: 38928 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38928 Log: * doc/syntax/calling_methods.rdoc: Added a Method Lookup section. * doc/syntax/refinements.rdoc (Method Lookup): Clarified that refinement methods are looked up in classes, not instances. Modified files: trunk/ChangeLog trunk/doc/syntax/calling_methods.rdoc trunk/doc/syntax/refinements.rdoc Index: doc/syntax/calling_methods.rdoc =================================================================== --- doc/syntax/calling_methods.rdoc (revision 38927) +++ doc/syntax/calling_methods.rdoc (revision 38928) @@ -322,3 +322,28 @@ avoid a warning. https://github.com/ruby/ruby/blob/trunk/doc/syntax/calling_methods.rdoc#L322 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. + Index: doc/syntax/refinements.rdoc =================================================================== --- doc/syntax/refinements.rdoc (revision 38927) +++ doc/syntax/refinements.rdoc (revision 38928) @@ -188,7 +188,7 @@ called: https://github.com/ruby/ruby/blob/trunk/doc/syntax/refinements.rdoc#L188 == Method Lookup -When looking up a method for a class +C+ Ruby checks: +When looking up a method for an instance of class +C+ Ruby checks: * If refinements are active for +C+, in the reverse order they were activated: * The prepended modules from the refinement for +C+ Index: ChangeLog =================================================================== --- ChangeLog (revision 38927) +++ ChangeLog (revision 38928) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jan 24 16:54:34 2013 Eric Hodel <drbrain@s...> + + * doc/syntax/calling_methods.rdoc: Added a Method Lookup section. + * doc/syntax/refinements.rdoc (Method Lookup): Clarified that + refinement methods are looked up in classes, not instances. + Thu Jan 24 16:49:17 2013 Marc-Andre Lafortune <ruby-core@m...> * enum.c (enum_zip): Fix error message -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/