diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-13 12:41:24 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-13 12:41:24 +0000 |
commit | 76e30054317d1f56137e6ae46e494b1c43f4a85e (patch) | |
tree | 6bfb32abbaea34d386a5bbc3b0f3b03762dd9b0f | |
parent | b3b6698e2f05ddf186e71153f81b76098222a6b0 (diff) |
* 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].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | proc.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1264,6 +1264,32 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod) 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) { |