1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval_proc.c (method_receiver): add new method to get the bound

receiver of the method object.  [ruby-talk:234949]

* eval_proc.c (method_name): new method to get the name of a
  method.

* eval_proc.c (method_owner): a new method to get the class or
  module that defines the method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-01-20 14:25:07 +00:00
parent 3b5dbc4b06
commit 0fe77cd26b
2 changed files with 64 additions and 0 deletions

View file

@ -12,6 +12,17 @@ Sat Jan 20 11:18:49 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_win32ole.rb: ditto.
Sat Jan 20 06:45:21 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval_proc.c (method_receiver): add new method to get the bound
receiver of the method object. [ruby-talk:234949]
* eval_proc.c (method_name): new method to get the name of a
method.
* eval_proc.c (method_owner): a new method to get the class or
module that defines the method.
Fri Jan 19 17:12:23 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (Init_win32ole): add WIN32OLE_VARIANT::Empty,

53
proc.c
View file

@ -790,6 +790,54 @@ method_unbind(obj)
return method;
}
/*
* call-seq:
* meth.receiver => object
*
* Returns the bound receiver of the method object.
*/
static VALUE
method_receiver(VALUE obj)
{
struct METHOD *data;
Data_Get_Struct(obj, struct METHOD, data);
return data->recv;
}
/*
* call-seq:
* meth.name => string
*
* Returns the name of the method.
*/
static VALUE
method_name(VALUE obj)
{
struct METHOD *data;
Data_Get_Struct(obj, struct METHOD, data);
return rb_str_new2(rb_id2name(data->id));
}
/*
* call-seq:
* meth.owner => class_or_module
*
* Returns the class or module that defines the method.
*/
static VALUE
method_owner(VALUE obj)
{
struct METHOD *data;
Data_Get_Struct(obj, struct METHOD, data);
return data->klass;
}
/*
* call-seq:
* obj.method(sym) => method
@ -1492,6 +1540,9 @@ Init_Proc()
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
rb_define_method(rb_cMethod, "receiver", method_receiver, 0);
rb_define_method(rb_cMethod, "name", method_name, 0);
rb_define_method(rb_cMethod, "owner", method_owner, 0);
rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
@ -1506,6 +1557,8 @@ Init_Proc()
rb_define_method(rb_cUnboundMethod, "arity", method_arity_m, 0);
rb_define_method(rb_cUnboundMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cUnboundMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cUnboundMethod, "name", method_name, 0);
rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0);
rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
/* Module#*_method */