Commit 4ac31089 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2261 from take-cheeze/fix_2259

Fix #2259 .
parents 41b46ca1 49cf4776
...@@ -984,16 +984,11 @@ basic_obj_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym id, int pub) ...@@ -984,16 +984,11 @@ basic_obj_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym id, int pub)
static mrb_value static mrb_value
obj_respond_to(mrb_state *mrb, mrb_value self) obj_respond_to(mrb_state *mrb, mrb_value self)
{ {
mrb_value *argv; mrb_value mid;
mrb_int argc;
mrb_value mid, priv;
mrb_sym id, rtm_id; mrb_sym id, rtm_id;
mrb_bool respond_to_p = TRUE; mrb_bool priv = FALSE, respond_to_p = TRUE;
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "o|b", &mid, &priv);
mid = argv[0];
if (argc > 1) priv = argv[1];
else priv = mrb_nil_value();
if (mrb_symbol_p(mid)) { if (mrb_symbol_p(mid)) {
id = mrb_symbol(mid); id = mrb_symbol(mid);
...@@ -1017,13 +1012,14 @@ obj_respond_to(mrb_state *mrb, mrb_value self) ...@@ -1017,13 +1012,14 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
} }
if (respond_to_p) { if (respond_to_p) {
respond_to_p = basic_obj_respond_to(mrb, self, id, !mrb_test(priv)); respond_to_p = basic_obj_respond_to(mrb, self, id, !priv);
} }
if (!respond_to_p) { if (!respond_to_p) {
rtm_id = mrb_intern_lit(mrb, "respond_to_missing?"); rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
if (basic_obj_respond_to(mrb, self, rtm_id, !mrb_test(priv))) { if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) {
return mrb_funcall_argv(mrb, self, rtm_id, argc, argv); mrb_value args[] = { mid, mrb_bool_value(priv) };
return mrb_funcall_argv(mrb, self, rtm_id, 2, args);
} }
} }
return mrb_bool_value(respond_to_p); return mrb_bool_value(respond_to_p);
......
...@@ -451,6 +451,14 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do ...@@ -451,6 +451,14 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do
Test4RespondTo.new.respond_to?(1) Test4RespondTo.new.respond_to?(1)
end end
assert_raise ArgumentError do
Test4RespondTo.new.respond_to?
end
assert_raise ArgumentError do
Test4RespondTo.new.respond_to? :a, true, :aa
end
assert_true respond_to?(:nil?) assert_true respond_to?(:nil?)
assert_true Test4RespondTo.new.respond_to?(:valid_method) assert_true Test4RespondTo.new.respond_to?(:valid_method)
assert_true Test4RespondTo.new.respond_to?('valid_method') assert_true Test4RespondTo.new.respond_to?('valid_method')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment