This project is archived and is in readonly mode.

#3164 ✓resolved
Paul Gillard

Instantiate through initialize_copy when cloning

Reported by Paul Gillard | September 8th, 2009 @ 10:49 AM

As discussed here I'm attaching a patch which overrides #initialize_copy rather than #clone in order to implement cloning of AR objects. This will allow AR classes to implement deep cloning of attributes much more easily, for example:

  def initialize_copy(other)
    self.an_association = other.an_association

This patch isn't intended to be the finished article as I have two particular points on which I'd appreciate some feedback.

Firstly, I'm having to call the after_initialize callback near the top of #initialize_copy in order to get the test suite to pass. This doesn't seem right to me and I've documented my thoughts in the patch file.

Secondly, #initialize allows a block to be passed in. Should #initialize_copy do a similar thing? If so I'll add a test and relevant code.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>


Referenced by