ruby-changes:12390
From: yugui <ko1@a...>
Date: Mon, 13 Jul 2009 21:41:46 +0900 (JST)
Subject: [ruby-changes:12390] Ruby:r24089 (trunk): * proc.c (Kernel#define_singleton_method): rdoc. based on a patch by
yugui 2009-07-13 21:41:24 +0900 (Mon, 13 Jul 2009) New Revision: 24089 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24089 Log: * proc.c (Kernel#define_singleton_method): rdoc. based on a patch by Marc-Andre Lafortune <ruby-core-mailing-list AT marc-andre.ca>. [ruby-core:23944]. Modified files: trunk/proc.c Index: proc.c =================================================================== --- proc.c (revision 24088) +++ proc.c (revision 24089) @@ -1264,6 +1264,32 @@ return body; } +/* + * call-seq: + * define_singleton_method(symbol, method) => new_method + * define_singleton_method(symbol) { block } => proc + * + * Defines a singleton method in the receiver. The _method_ + * parameter can be a +Proc+ or +Method+ object. + * If a block is specified, it is used as the method body. + * + * class A + * class << self + * def class_name + * to_s + * end + * end + * end + * A.define_singleton_method(:who_am_i) do + * "I am: #{class_name}" + * end + * A.who_am_i # ==> "I am: A" + * + * guy = "Bob" + * guy.define_singleton_method(:hello) { "#{self}: Hello there!" } + * guy.hello # => "Bob: Hello there!" + */ + static VALUE rb_obj_define_method(int argc, VALUE *argv, VALUE obj) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/