mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #1194 from carsonmcdonald/rtomissingimpl
Implement respond_to_missing?
This commit is contained in:
+8
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user