[wxruby-users] use of Marshal with wxruby classes

Robert Anderson rwa000 at gmail.com
Fri Jan 4 18:08:54 EST 2008


Is it possible to use Marshal with wxruby classes to serialize an
application's state?

I tried a minimal example of simply serializing a minimal frame object, and
I get the error "no marshal_dump is defined for class MinimalFrame".

I don't fully understand this because I also tried another minimal example
of dumping a class which did not defined a marshal_dump, and it worked
fine.  Is there some reason this has been disabled in wxruby classes?
Sorry, I picked up ruby a few days ago so I may be missing something
obvious.

Here's a test program showing that the simple class will serialize but the
simple frame will not.

#!/usr/bin/env ruby

require 'wx'
include Wx

class MinimalClass
  def initialize
    @data = 1234
  end

  def save
    File.open("dump-class","w+") do |f|
      Marshal.dump(self, f)
    end
  end

end

class MinimalFrame < Frame
  def initialize(title)
    # The main application frame has no parent (nil)
    super(nil, :title => title, :size => [ 700, 400 ])
    @data = 1234
  end

  def save
    File.open("dump-frame","w+") do |f|
      Marshal.dump(self, f)
    end
  end

end


App.run do

  obj = MinimalClass.new
  obj.save

  self.app_name = 'Minimal'
  frame = MinimalFrame.new("Minimal wxRuby App")
  frame.save
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080104/a4ae5d73/attachment.html 


More information about the wxruby-users mailing list