Issue #21858 has been updated by ccmywish (Aoran Zeng).
as @Dan0042 (Daniel DeLorme) pointed out for example
Just to clarify — maybe I missed something, but it seems there might be a slight misunderstanding. In his comment, Daniel mainly provided historical context about when `to_h` was introduced and suggested that the current behavior of `Hash()` was likely an oversight. I couldn't find where he pointed out a "big side effect." If there is a specific example he mentioned, I may have overlooked it; otherwise, could this possibly be referring to a different discussion? <br>
What do you think?
Speaking from my own programming habits, I almost never use conversion functions like `Array()` or `Integer()` — I tend to explicitly call `.to_xxx` methods in a more OO style. In fact, I only discovered that Ruby provides these global-style functions when I was reading the `Kernel` module documentation. Given that these functions are provided, I believe they should behave in a predictable and consistent way. Otherwise, **users are left to memorize special cases** — like the fact that `Hash()` does not consider `to_h`, unlike its counterparts. Regarding the potential side effects of this change: since I don’t widely use these conversion functions myself, it’s hard for me to assess how much impact this would have in the wider community. Perhaps it would be worthwhile to gather some usage feedbacks from other developers. ---------------------------------------- Feature #21858: `Kernel#Hash` considers `to_h` too https://bugs.ruby-lang.org/issues/21858#change-116408 * 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/