I’m new to Ruby and am having difficulty getting a deep_copy method
working. I think I’m just doing something stupid with namespaces, but
I’m not sure eactly what. Here’s what I’ve got:
module Bio
module PDBUtils
[snip!]
def deep_copy
puts "Trying to copy #{self.class}"
Marshal.load(Marshal.dump(self))
end
end
class PDB
include PDBUtils
[snip!]
end
end
I get a new PDB object fine:
structure = Bio::PDB.new()
but when I try and use deep_copy I get an error:
structure2 = structure.deep_copy
Trying to copy Bio::PDB
in ‘dump’: can’t dump anonymous module #Module:0x403738c
(TypeError)
Googling for this error reveals that Marshal.dump was fixed in 1.8 to
not allow dumping of anonymous modules. Unfortunately I’m not sure I
understand why it’s saying I’m giving it an anonymous module. Doesn’t
the ‘Trying to copy Bio::PDB’ output mean that I’m giving it a
Bio::PDB object to dump?
If somone could explain exactly what an anonymous module is, and why
I’ve got one here I’d really appreciate it.
At Fri, 13 Feb 2004 02:34:57 +0900,
Alex Gutteridge wrote in [ruby-talk:92728]:
Googling for this error reveals that Marshal.dump was fixed in 1.8 to
not allow dumping of anonymous modules. Unfortunately I’m not sure I
understand why it’s saying I’m giving it an anonymous module. Doesn’t
the ‘Trying to copy Bio::PDB’ output mean that I’m giving it a
Bio::PDB object to dump?
At Fri, 13 Feb 2004 02:34:57 +0900,
Alex Gutteridge wrote in [ruby-talk:92728]:
Googling for this error reveals that Marshal.dump was fixed in 1.8 to
not allow dumping of anonymous modules. Unfortunately I’m not sure I
understand why it’s saying I’m giving it an anonymous module. Doesn’t
the ‘Trying to copy Bio::PDB’ output mean that I’m giving it a
Bio::PDB object to dump?
Sorry, I’m not sure I understand. Are you saying that this is a bug in
Ruby that is now fixed? I’m using 1.8.1 as well, but my build date is
earlier than yours:
$ruby -v
ruby 1.8.1 (2003-12-25) [i686-linux]
Would I need to build Ruby from the latest cvs snapshot to get this
working?