Hello,
Although Ruby has a rich set of primitive data types and structures,
the Hash seems neglected in the Ruby API in comparison to its peers:
| | Kernel | Implicit | Explicit | NilClass |
Class | method | conversion | conversion | conversion |
---|---|---|---|---|
String | String() | to_str | to_s | nil.to_s |
Integer | Integer() | to_int | to_i | nil.to_i |
Float | Float() | to_float | to_f | nil.to_f |
Array | Array() | to_ary | to_a | nil.to_a |
Hash | MISSING | to_hash | MISSING | MISSING |
To rectify this un-orthogonality, I created a small Ruby library:
(gem) equal_rights_for_hash | RubyGems.org | your community gem host
(code) GitHub - sunaku/equal_rights_for_hash: Adds Kernel#Hash() and generic #to_h() methods.
(docs) File: README — Documentation for equal_rights_for_hash (0.0.4)
For more information, please see my proposal to incorporate the
above functionality into Ruby’s core API on the Ruby Issue Tracker:
Thanks for your consideration.