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