diff --git a/proc.c b/proc.c index 40628f1268..810fe79c92 100644 --- a/proc.c +++ b/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! * # */ @@ -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