Using Array.new inside itself creates internal references?

I’m fairly certain this is expected behavior. Array is a class, and therefore will be referenced. What you need to do is use a block to create a new array instance for each index. https://play.crystal-lang.org/#/r/77qx

This happens because Array.new doesn’t call dup on the values you’re filling it with.

1 Like