I wanted to get an object on production and do an exact replica( copy over its contents) to another object of same type. I tried doing this in 3 ways from ruby console which none of them worked:
Let's say you have the
ttas the first object you want to copy over andtt2as the replica object. The first approach I tried is cloning the arraytt2.patients = tt.urls.patients tt2.doctors = tt.segments.doctors tt2.hospitals = tt.pixels.hospitalsSecond approach I tried is duplicating the array which is actually the same as cloning the array:
tt2.patients = tt.patients.dup tt2.doctors = tt.doctors.dup tt2.hospitals = tt.hospitals.dupThird approach I tried is marhsalling.
tt2.patients = Marshal.load(Marshal.dump(tt.patients)) tt2.doctors = Marshal.load(Marshal.dump(tt.doctors)) tt2.hospitals = Marshal.load(Marshal.dump(tt.hospitals))
None of the above works for deep copying from one array to another. After trying out each approach individually above, all the contents of the first object (tt) are nullified (patients, doctors and hospitals are gone). Do you have any other ideas on copying the contents of one object to another? Thanks.