summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-20 05:13:28 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-20 05:13:28 (GMT)
commit629d26ef3a41cf585f92ac6d0d8b0a17a47c3daa (patch)
treeb2fe87f9c90528d9506a8dda119954ffa13803bd /vm_method.c
parent24da2db3e1eab67b6ee7be00d75b73beb273a4c4 (diff)
vm_eval.c: share with rb_obj_respond_to
* vm_eval.c (check_funcall_respond_to): share the behavior with rb_obj_respond_to. [ruby-core:70460] [Bug #11465] * vm_method.c (vm_respond_to): extract from rb_obj_respond_to and merge r39881. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/vm_method.c b/vm_method.c
index fd000fa..e74de0d 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1829,10 +1829,9 @@ basic_obj_respond_to(VALUE obj, ID id, int pub)
}
}
-int
-rb_obj_respond_to(VALUE obj, ID id, int priv)
+static int
+vm_respond_to(rb_thread_t *th, VALUE klass, VALUE obj, ID id, int priv)
{
- VALUE klass = CLASS_OF(obj);
VALUE defined_class;
const ID resid = idRespond_to;
const rb_method_entry_t *const me =
@@ -1845,12 +1844,20 @@ rb_obj_respond_to(VALUE obj, ID id, int priv)
else {
int argc = 1;
VALUE args[2];
+ VALUE result;
const rb_callable_method_entry_t *cme;
+ const rb_block_t *passed_block = th->passed_block;
args[0] = ID2SYM(id);
args[1] = Qtrue;
if (priv) {
- if (rb_method_entry_arity(me) != 1) {
+ argc = rb_method_entry_arity(me);
+ if (argc > 2) {
+ rb_raise(rb_eArgError,
+ "respond_to? must accept 1 or 2 arguments (requires %d)",
+ argc);
+ }
+ if (argc != 1) {
argc = 2;
}
else if (!NIL_P(ruby_verbose)) {
@@ -1871,11 +1878,19 @@ rb_obj_respond_to(VALUE obj, ID id, int priv)
}
}
cme = prepare_callable_method_entry(defined_class, resid, me);
- return RTEST(vm_call0(GET_THREAD(), obj, resid, argc, args, cme));
+ result = vm_call0(th, obj, resid, argc, args, cme);
+ th->passed_block = passed_block;
+ return RTEST(result);
}
}
int
+rb_obj_respond_to(VALUE obj, ID id, int priv)
+{
+ return vm_respond_to(GET_THREAD(), CLASS_OF(obj), obj, id, priv);
+}
+
+int
rb_respond_to(VALUE obj, ID id)
{
return rb_obj_respond_to(obj, id, FALSE);