It could maybe help to give some context why you end up with a nested hash of unknown structure and then want to import it into strict types in the first place.
Not easy to explain!
The hash is used to parameterize the operation of an application and is in the user’s hands.
The hash structure is not really unknown, but can be more or less complete, depending on the user’s use.
The original idea was to facilitate programming by taking into account only the values provided, but this was probably a bad idea. I’ve therefore abandoned it and considered taking into account a hash containing all possible data.
Who can do more can do less!
In fact, the application in question is a library, still in the development phase, designed for Crystal developers to format tables in Terminal mode (a primitive version of Tablo was released in 2021).
To use this library, the developer builds and fills the hash as part of his own application.
To come back to the original question, adding a method (Hash.from ?) meeting my initial wish would not, in my opinion, be uninteresting.
So, in the example given:
It seems like a configuration class could be a much better option for this… Bringing type-safety, easy discoverability and documentation.
Nested hashes are a bit frowned upon in Crystal (and I guess in any statially typed langauge). Especially the extensive use for configuration as in Ruby doesn’t translate well. It’s usually much better to define a type or configuration.