Commit a70419bc authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1194 from carsonmcdonald/rtomissingimpl

Implement respond_to_missing?
parents cc512dd8 93b23357
......@@ -965,7 +965,7 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
mrb_value *argv;
int argc;
mrb_value mid, priv;
mrb_sym id;
mrb_sym id, rtm_id;
mrb_bool respond_to_p;
mrb_get_args(mrb, "*", &argv, &argc);
......@@ -976,6 +976,13 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
respond_to_p = basic_obj_respond_to(mrb, self, id, !mrb_test(priv));
if(!respond_to_p) {
rtm_id = mrb_intern2(mrb, "respond_to_missing?", 19);
if(basic_obj_respond_to(mrb, self, rtm_id, !mrb_test(priv))) {
return mrb_funcall_argv(mrb, self, rtm_id, argc, argv);
}
}
return mrb_bool_value(respond_to_p);
}
......
......@@ -392,3 +392,16 @@ assert('Kernel#!=') do
(str1 != str3) == true and
(str2 != str1) == false
end
assert('Kernel#respond_to_missing?') do
class Test4RespondToMissing
def respond_to_missing?(method_name, include_private = false)
method_name == :a_method
end
end
Test4RespondToMissing.new.respond_to?(:a_method) == true and
Test4RespondToMissing.new.respond_to?(:no_method) == false
end
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