Marshal/Serialization Question

Hello all,

I’m trying to Marshal some Ruby objects to file and I have a question
about parent classes. Say I have the following:

class Device
@@id = 0
@@id_map = Hash.new
@@device_map = Hash.new

def initialize(*args)
id = @@id += 1
@@id_map[self] = id
@@device_map[id] = self
end

def self.id(device)
return @@id_map[device]
end

def self.device(id)
return @@device_map[id]
end
end

class Foo < Device
def initialize
super
end
end

Now, if I create a Foo class, dump it to file and then load it again
using Marshal, should I be able to use the id and device methods in the
parent class or will the class variables not be dumped and loaded?


Thanks!
Bryan

On 19.08.2008 23:38, Bryan R. wrote:

def initialize(*args)
return @@device_map[id]
using Marshal, should I be able to use the id and device methods in the
parent class or will the class variables not be dumped and loaded?

Try it out. I’d say, most likely they are not dumped as classes are not
serialized IIRC. Class variables are evil anyway… :slight_smile:

Kind regards

robert