From 57540fbf6cc90a2265299950524edcbf613a0cdd Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 26 Feb 2022 22:01:52 +0900 Subject: [PATCH] object.c: improve handling of the broken `inspect` method. When `inspect` method returns non-string value, it will return a string given from `to_s` (and if `to_s` fails, will raise an exception). --- src/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/object.c b/src/object.c index a42293016..b430f2057 100644 --- a/src/object.c +++ b/src/object.c @@ -606,7 +606,11 @@ mrb_check_hash_type(mrb_state *mrb, mrb_value hash) MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj) { - return mrb_obj_as_string(mrb, mrb_funcall_id(mrb, obj, MRB_SYM(inspect), 0)); + mrb_value v = mrb_funcall_id(mrb, obj, MRB_SYM(inspect), 0); + if (!mrb_string_p(v)) { + v = mrb_obj_as_string(mrb, obj); + } + return v; } MRB_API mrb_bool