Marshal.dump - anonymous module


(AlexG) #1

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
alexg@ebi.ac.uk


(Nobuyoshi Nakada) #2

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

···


Nobu Nakada


(AlexG) #3

nobu.nokada@softhome.net wrote in message news:200402121744.i1CHiVFH026372@sharui.nakada.niregi.kanuma.tochigi.jp

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
alexg@ebi.ac.uk


(Nobuyoshi Nakada) #4

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.

···


Nobu Nakada