5 ms·
But caching doesn't required here. Hash.new calls block only if value isn't initialialized.
by oddx 3y ago
But caching doesn't required here. Hash.new calls block only if value isn't initialialized.
- devoutsalsa 3y agoI just did it for fun. This particular recursive approach is super slow for numbers of nontrivial size, so I was just curious if I could even make the caching work in the block. It's not worth optimizing a suboptimal query when a more efficient option is available anyway.
- deleted 3y ago[deleted]
- sinkwool 3y agoYou don't need the `unless k.key? v` guard. The `Hash.new` block only gets called when the key is not present in the hash.
- devoutsalsa 3y agoThe caching makes it faster the trade off being more using more memory. I just wanted to see if it’d work.