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