mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									96af5360a4
								
							
						
					
					
						commit
						dbcf20069a
					
				
					 3 changed files with 32 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,9 @@
 | 
			
		|||
Thu Jan 24 16:54:34 2013  Eric Hodel  <drbrain@segment7.net>
 | 
			
		||||
 | 
			
		||||
	* 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@marc-andre.ca>
 | 
			
		||||
 | 
			
		||||
	* enum.c (enum_zip): Fix error message
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -188,7 +188,7 @@ called:
 | 
			
		|||
 | 
			
		||||
== 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+
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue