Marshal.dump - anonymous module

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::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.

Thanks for your time.

Alex Gutteridge
(e-mail address removed)
 
N

nobu.nokada

Hi,

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?

It was a fixed bug.

$ ruby-1.8 -v bio.rb
ruby 1.8.1 (2004-02-10) [i686-linux]
Trying to copy Bio::pDB
#<Bio::pDB:0x40317ca0>
 
A

Alex Gutteridge

Hi,

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?

It was a fixed bug.

$ ruby-1.8 -v bio.rb
ruby 1.8.1 (2004-02-10) [i686-linux]
Trying to copy Bio::pDB
#<Bio::pDB:0x40317ca0>

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?

Alex Gutteridge
(e-mail address removed)
 
N

nobu.nokada

Hi,

At Fri, 13 Feb 2004 23:54:56 +0900,
Alex Gutteridge wrote in [ruby-talk:92790]:
Would I need to build Ruby from the latest cvs snapshot to get this
working?

Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top