Mike Gold <mike.gold.4433 / gmail.com> writes:

> Mike Gold wrote:
>> def Array.multi(*dimensions)
>>   dimensions.reverse.inject(nil) { |result, dim|
>>     Array.new(dim) { result ? result.dup : nil }
>>   }
>> end
>
> My mistake.  Array#dup is not a recursive deep copy.
>
> def Array.multi(*dimensions)
>   dimensions.reverse.inject(nil) { |result, dim|
>     Array.new(dim) { Marshal.load(Marshal.dump(result)) }
>   }
> end

Yearning for macros...