mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Add details about parameters to define_method doc (#2165)
When we use `define_method` and `define_singleton_method`, if we supply block parameters to a block then a generated method has corresponding parameters. However, the doc doesn't mention it, so this info has been added.
This commit is contained in:
		
							parent
							
								
									409ce8c3da
								
							
						
					
					
						commit
						74726691ba
					
				
					 1 changed files with 12 additions and 2 deletions
				
			
		
							
								
								
									
										14
									
								
								proc.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								proc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1935,8 +1935,10 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid)
 | 
			
		|||
 *
 | 
			
		||||
 *  Defines an instance method in the receiver. The _method_
 | 
			
		||||
 *  parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
 | 
			
		||||
 *  If a block is specified, it is used as the method body. This block
 | 
			
		||||
 *  is evaluated using #instance_eval.
 | 
			
		||||
 *  If a block is specified, it is used as the method body.
 | 
			
		||||
 *  If a block or the _method_ parameter has parameters,
 | 
			
		||||
 *  they're used as method parameters.
 | 
			
		||||
 *  This block is evaluated using #instance_eval.
 | 
			
		||||
 *
 | 
			
		||||
 *     class A
 | 
			
		||||
 *       def fred
 | 
			
		||||
| 
						 | 
				
			
			@ -1946,6 +1948,7 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid)
 | 
			
		|||
 *         self.class.define_method(name, &block)
 | 
			
		||||
 *       end
 | 
			
		||||
 *       define_method(:wilma) { puts "Charge it!" }
 | 
			
		||||
 *       define_method(:flint) {|name| puts "I'm #{name}!"}
 | 
			
		||||
 *     end
 | 
			
		||||
 *     class B < A
 | 
			
		||||
 *       define_method(:barney, instance_method(:fred))
 | 
			
		||||
| 
						 | 
				
			
			@ -1953,6 +1956,7 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid)
 | 
			
		|||
 *     a = B.new
 | 
			
		||||
 *     a.barney
 | 
			
		||||
 *     a.wilma
 | 
			
		||||
 *     a.flint('Dino')
 | 
			
		||||
 *     a.create_method(:betty) { p self }
 | 
			
		||||
 *     a.betty
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -1960,6 +1964,7 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid)
 | 
			
		|||
 *
 | 
			
		||||
 *     In Fred
 | 
			
		||||
 *     Charge it!
 | 
			
		||||
 *     I'm Dino!
 | 
			
		||||
 *     #<B:0x401b39e8>
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2064,6 +2069,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
 | 
			
		|||
 *  Defines a singleton method in the receiver. The _method_
 | 
			
		||||
 *  parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
 | 
			
		||||
 *  If a block is specified, it is used as the method body.
 | 
			
		||||
 *  If a block or a method has parameters, they're used as method parameters.
 | 
			
		||||
 *
 | 
			
		||||
 *     class A
 | 
			
		||||
 *       class << self
 | 
			
		||||
| 
						 | 
				
			
			@ -2080,6 +2086,10 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
 | 
			
		|||
 *     guy = "Bob"
 | 
			
		||||
 *     guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
 | 
			
		||||
 *     guy.hello    #=>  "Bob: Hello there!"
 | 
			
		||||
 *
 | 
			
		||||
 *     chris = "Chris"
 | 
			
		||||
 *     chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
 | 
			
		||||
 *     chris.greet("Hi") #=> "Hi, I'm Chris!"
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue