adamantium icon indicating copy to clipboard operation
adamantium copied to clipboard

Memoize Question: DUP vs. Clone

Open tjchambers opened this issue 9 years ago • 2 comments

I was using Adamantium to help drive some immutability into my code, and noted a key issue in testing.

I was memoizing under Adamantium::Flat a result from another class that was returning an ActiveRecord model object (a single one). Because Adamantium uses a .dup method before freezing, the result is the ActiveRecord object has the ID removed.

My understanding is that using a clone method to replicate before freezing would preserve the ID (a crucial element for me). I know there are subtle differences between the two methods (not sure all of them - one of which is clone preserves previously frozen state - probably not relevant here).

My question is by using dup method instead of clone s this a bug or an intention?

tjchambers avatar May 19 '15 19:05 tjchambers

I neglected to point out that I was able to work around my issue by freezing my returned ActiveRecord object - so my question is more for consideration than a roadblock. It was unexpected behavior however and confused me for a bit.

tjchambers avatar May 19 '15 19:05 tjchambers

ping

tjchambers avatar Oct 11 '15 22:10 tjchambers