* Patrick Bennett (patrick.bennett / inin.com) wrote: > Paul E.C. Melis wrote: > > >Hmmm, according to the Pickaxe book "In general, clone and dup may have > >different semantics in descendent classes. While clone is used to duplicate > >an object, including its internal state, dup typically uses the class of > >the > >descendent object to create the new instance." > > > >I must say that this doesn't make it clearer for myself either :/ > > > Agreed. There's also the problem that ruby doesn't seem to have a > deep-copy. If an object doesn't provide its own deep-copy equivalent, > internal objects still reference the same object-id's. > a = b.dup > A's objects may have new clone's of b's values, but internal objects may > still point to the same object-id, so change's to a may affect b. > I'd love to have some help on this one. It seems like an odd ommision - > or are classes supposed to impliment a copy-constructor like equivalent > ? a = AClass.new( b) ? Can't you deep copy using Marshal? a = Marshal.restore(Marshal.dump(b)) Tom. -- .^. .-------------------------------------------------------. /V\ | Tom Gilbert, London, England | http://linuxbrit.co.uk | /( )\ | Open Source/UNIX consultant | tom / linuxbrit.co.uk | ^^-^^ `-------------------------------------------------------'