From baeeb5e435f49f3abb60a229874aa6a5e1f6b43e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 21 Dec 2024 08:52:23 +0900 Subject: [PATCH] hash.c (mrb_hash_to_s): print `:sym => val` as `sym: val` Ruby 3.4 changed the format of hash string representation. We follow. --- src/hash.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/hash.c b/src/hash.c index 93af8a4bf..d4268d33c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1858,11 +1858,18 @@ mrb_hash_to_s(mrb_state *mrb, mrb_value self) struct RHash *h = mrb_hash_ptr(self); H_EACH(h, entry) { if (i++ > 0) mrb_str_cat_lit(mrb, ret, ", "); - H_CHECK_MODIFIED(mrb, h) { - mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key)); + if (mrb_symbol_p(entry->key)) { + mrb_str_cat_str(mrb, ret, mrb_obj_as_string(mrb, entry->key)); + mrb_gc_arena_restore(mrb, ai); + mrb_str_cat_lit(mrb, ret, ": "); + } + else { + H_CHECK_MODIFIED(mrb, h) { + mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key)); + } + mrb_gc_arena_restore(mrb, ai); + mrb_str_cat_lit(mrb, ret, " => "); } - mrb_gc_arena_restore(mrb, ai); - mrb_str_cat_lit(mrb, ret, " => "); H_CHECK_MODIFIED(mrb, h) { mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->val)); }