alilland alilland - 1 year ago 61
Ruby Question

How can i duplicate a record with ruby (outside of rails)?

I have a hash with an object id of 19475160, I need to clone my hash, how would I go about doing this? Every google search and article I have found points me to rails solutions but I cant find anything that is a regular ruby solution.

Answer Source

This will do a shallow copy of an object:

 obj2 = obj.clone

This will do a deep copy of an object:

  obj2 = Marshal.load(Marshal.dump(obj))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download