[ruby-core:120070] [Ruby master Bug#20898] Backport https://github.com/ruby/ruby/pull/9737 to Ruby 3.3 and 3.2