Re:Ruby's Hash Is A Swiss-Army Knife
by devoutsalsa on Monday August 21, 2023 @07:01AM
(#37207840)
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.
[ Parent
| on HN ]
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.
Re:Ruby's Hash Is A Swiss-Army Knife
by devoutsalsa on Monday August 21, 2023 @08:43AM
(#37208745)
The caching makes it faster the trade off being more using more memory. I just wanted to see if it’d work.