How to append to an Array that is a default Value of a Hash?

Beware of the defualt_value semantics. You will end up with a shared array.

Hash.new can a block to lazy initialize entries. That might be more helpful.

Also, relevant old issue: https://github.com/crystal-lang/crystal/issues/4376

2 Likes