dkubb / adamantium

Create immutable objects
MIT License
373 stars 13 forks source link

Memoize Question: DUP vs. Clone #33

Open tjchambers opened 9 years ago

tjchambers commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

ping