mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
e04e2e0bb3
commit
3be6ebc5ce
4 changed files with 74 additions and 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
|
||||
|
|
6
NEWS
6
NEWS
|
@ -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.
|
||||
|
|
54
eval.c
54
eval.c
|
@ -9118,6 +9118,57 @@ method_unbind(obj)
|
|||
return method;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue