Ask Hack Learn Share!
A simplified version of the code is this
this code hides different problems that can happen accessing the hash and the array in the value of the hash, e.g. the hash is nil, the value of key_to_an_array
can be nil or not respond to first
, and maybe even more, you name it. More important is that the code is not clearly showing the problem, rather it is hiding things by saying whatever the problem it is, just return an empty hash.
After a while we analyzed the cases and things were not that easy, edge cases appeared, so it was not just a matter of style anymore, so we came up with this other version
We’ve ran some benchmarks and the results are almost the same in both implementations for amounts below 1000, they start to differ above 100 000 which we will never reach in a request anyways. But still it was worth fixing.
Kudos to Raúl Galindo for making me improve what I deliver.