A
Alex Gutteridge
Hi,
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:DB.new()
but when I try and use deep_copy I get an error:
structure2 = structure.deep_copy
Trying to copy Bio:DB
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:DB' output mean that I'm giving it a
Bio:DB 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.
Thanks for your time.
Alex Gutteridge
(e-mail address removed)
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:DB.new()
but when I try and use deep_copy I get an error:
structure2 = structure.deep_copy
Trying to copy Bio:DB
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:DB' output mean that I'm giving it a
Bio:DB 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.
Thanks for your time.
Alex Gutteridge
(e-mail address removed)