diff options
author | kazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-15 10:07:59 +0000 |
---|---|---|
committer | kazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-15 10:07:59 +0000 |
commit | 3be6ebc5ce37dc5f3800484d525e501f66d51d8e (patch) | |
tree | 79b09fa0a7ef993f7dfd7afcc22c3cb8b9194144 | |
parent | e04e2e0bb33e48f556037d786db60ac2059b2af9 (diff) |
* eval.c (method_receiver, method_name, method_owner): New
methods; backported from 1.9. bug#19007
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | eval.c | 54 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 9 |
4 files changed, 74 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Apr 15 19:03:28 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> + + * eval.c (method_receiver, method_name, method_owner): New + methods; backported from 1.9. bug#19007 + Tue Apr 15 18:39:14 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> * lib/uri.rb, lib/uri/ldaps.rb: added LDAPS @@ -167,6 +167,12 @@ with all sufficient information, see the ChangeLog file. Return an enumerator if no block is given. + * Method#receiver + * Method#name + * Method#owner + + New methods. + * Numeric#step Return an enumerator if no block is given. @@ -9120,6 +9120,57 @@ method_unbind(obj) /* * call-seq: + * meth.receiver => object + * + * Returns the bound receiver of the method object. + */ + +static VALUE +method_receiver(obj) + 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(obj) + VALUE obj; +{ + struct METHOD *data; + + Data_Get_Struct(obj, struct METHOD, data); + return rb_str_new2(rb_id2name(data->oid)); +} + +/* + * call-seq: + * meth.owner => class_or_module + * + * Returns the class or module that defines the method. + */ + +static VALUE +method_owner(obj) + VALUE obj; +{ + struct METHOD *data; + + Data_Get_Struct(obj, struct METHOD, data); + return data->klass; +} + +/* + * call-seq: * obj.method(sym) => method * * Looks up the named method as a receiver in <i>obj</i>, returning a @@ -9739,6 +9790,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); diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index c30705cb15..b22c2cba62 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -39,4 +39,13 @@ class TestMethod < Test::Unit::TestCase um.bind(Base.new) end end + + def test_receiver_name_owner + o = Object.new + def o.foo; end + m = o.method(:foo) + assert_equal(o, m.receiver) + assert_equal("foo", m.name) + assert_equal(class << o; self; end, m.owner) + end end |