Turning Things Into Hashes
We have #to_h
for turning things into hashes.
It works as an identity function:
It works with nil
:
Does it work with arrays?
Yes, but only if it is an array of pairs:
It also works with Struct
and OpenStruct
:
You'll find that many other objects and gems support #to_h
when it makes sense.
Last updated