From: "mame (Yusuke Endoh) via ruby-core" Date: 2026-02-13T15:45:04+00:00 Subject: [ruby-core:124817] [Ruby Feature#21858] `Kernel#Hash` considers `to_h` too Issue #21858 has been updated by mame (Yusuke Endoh). If we assume that changing a call that previously raised an exception to return a value is always "a backward-compatible behavior addition," then by that logic, we could also make `Kernel#raise` return a value without issue. :-) I said `Kernel#Hash` is a strict conversion method. There could be users and existing code that rely on it raising an exception for unexpected input. That being said, I don't have a strong personal opinion on this proposal itself. I just wanted to clarify Matz's comment. ---------------------------------------- Feature #21858: `Kernel#Hash` considers `to_h` too https://bugs.ruby-lang.org/issues/21858#change-116437 * Author: ccmywish (Aoran Zeng) * Status: Open ---------------------------------------- 1. `Kernel#Integer` uses `to_int` first and `to_i` second 2. `Kernel#Array` uses `to_ary` first and `to_a` second 3. `Kernel#Hash` only uses `to_hash` I don't quite understand why there is a need for differential treatment here. I admit that maybe the only benefit of considering `to_h` secondly is that it enables multiple APIs to maintain consistency. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/