Hacker News new | ask | show | jobs
by oddx 1028 days ago
But caching doesn't required here. Hash.new calls block only if value isn't initialialized.
1 comments

I 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.
You 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.
The caching makes it faster the trade off being more using more memory. I just wanted to see if it’d work.