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.
相关问题
- facebook error invalid key hash for some devices
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- Bcrypt vs Hash in laravel
- uninitialized constant Mysql2::Client::SECURE_CONN
This is my helper class. It only converts Strings which are just numbers (Integer or Float).
This is a pretty straightforward recursive implementation (though having to handle both arrays and hashes adds a little trickiness).
And, hey, it even works: