Not so much philosophical today, so here’s something useful.
In Ruby, arguments are passed by reference, and using obj.clone / obj.dup may cause major headaches trying to figure out why your duplicated nested array is being changed while it shouldn’t.
Why isn’t it duplicated? It actually is, the first array is duplicated, but the nested elements are still references. A way to force everything to be duplicated for sure is to use Marshal library.
comments powered by Disqus