I have a hash of a random size, which may have values like "100", which I would like to convert to integers. I know I can do this using value.to_i if value.to_i.to_s == value, but I’m not sure how would I do that recursively in my hash, considering that a value can be either a string, or an array (of hashes or of strings), or another hash.
I have a hash of a random size, which may have values like 100
Share
This is a pretty straightforward recursive implementation (though having to handle both arrays and hashes adds a little trickiness).
And, hey, it even works: