Issue #21858 has been updated by Dan0042 (Daniel DeLorme). mame (Yusuke Endoh) wrote in #note-7:
I said `Kernel#Hash` is a strict conversion method.
It's true that `Integer()` is a strict conversion method, but `Array()` and `String()` are notably more lenient, and I've always seen `Hash()` as more similar to those two. Especially since `Hash()` already converts `nil` and `[]` to an empty hash, I don't think it can be considered a strict conversion method. In fact these two special cases are so weird, it's like `Hash()` already has partial support for #to_h
There could be users and existing code that rely on it raising an exception for unexpected input.
Normally, "expected input" is something that can be converted to Hash, and "unexpected input" is everything else. If Struct can be converted via `Hash()` it simply means there's a greater range of valid inputs. I would be very very surprised to see `Hash()` being used to exclude Struct objects specifically. If a developer wanted strict type validation, they would likely use `is_a?(Hash)` or `Hash.try_convert` or RBS or such. ---------------------------------------- Feature #21858: `Kernel#Hash` considers `to_h` too https://bugs.ruby-lang.org/issues/21858#change-116440 * 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/