Professional Web Applications Themes

Marshal.dump - anonymous module - Ruby

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

  1. #1

    Default Marshal.dump - anonymous module

    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
    ac.uk
    Alex Guest

  2. #2

    Default Re: Marshal.dump - anonymous module

    Hi,

    At Fri, 13 Feb 2004 02:34:57 +0900,
    Alex Gutteridge wrote in [ruby-talk:92728]: 

    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


    nobu.nokada@softhome.net Guest

  3. #3

    Default Re: Marshal.dump - anonymous module

    net wrote in message news:<nakada.niregi.kanuma.tochigi.jp>... 
    >
    > 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>[/ref]

    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
    ac.uk
    Alex Guest

  4. #4

    Default Re: Marshal.dump - anonymous module

    Hi,

    At Fri, 13 Feb 2004 23:54:56 +0900,
    Alex Gutteridge wrote in [ruby-talk:92790]: 

    Yes.

    --
    Nobu Nakada


    nobu.nokada@softhome.net Guest

Similar Threads

  1. Replies: 17
    Last Post: December 6th, 03:23 PM
  2. Ruby 1.8 and Marshal.load/Marshal.dump
    By Michael Davis in forum Ruby
    Replies: 0
    Last Post: October 10th, 10:15 PM
  3. Replies: 0
    Last Post: September 15th, 02:30 PM
  4. Can't marshal MatchData?
    By Gavin Sinclair in forum Ruby
    Replies: 3
    Last Post: August 6th, 12:20 PM
  5. Marshal efficiency
    By Gavin Sinclair in forum Ruby
    Replies: 2
    Last Post: July 20th, 05:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139