Skip to content

Commit baeeb5e

Browse files
committed
hash.c (mrb_hash_to_s): print :sym => val as sym: val
Ruby 3.4 changed the format of hash string representation. We follow.
1 parent e31869f commit baeeb5e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/hash.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,11 +1858,18 @@ mrb_hash_to_s(mrb_state *mrb, mrb_value self)
18581858
struct RHash *h = mrb_hash_ptr(self);
18591859
H_EACH(h, entry) {
18601860
if (i++ > 0) mrb_str_cat_lit(mrb, ret, ", ");
1861-
H_CHECK_MODIFIED(mrb, h) {
1862-
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key));
1861+
if (mrb_symbol_p(entry->key)) {
1862+
mrb_str_cat_str(mrb, ret, mrb_obj_as_string(mrb, entry->key));
1863+
mrb_gc_arena_restore(mrb, ai);
1864+
mrb_str_cat_lit(mrb, ret, ": ");
1865+
}
1866+
else {
1867+
H_CHECK_MODIFIED(mrb, h) {
1868+
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->key));
1869+
}
1870+
mrb_gc_arena_restore(mrb, ai);
1871+
mrb_str_cat_lit(mrb, ret, " => ");
18631872
}
1864-
mrb_gc_arena_restore(mrb, ai);
1865-
mrb_str_cat_lit(mrb, ret, " => ");
18661873
H_CHECK_MODIFIED(mrb, h) {
18671874
mrb_str_cat_str(mrb, ret, mrb_inspect(mrb, entry->val));
18681875
}

0 commit comments

Comments
 (0)