# Marshal/Serialization Question

**URL:** <https://www.ruby-forum.com/t/marshal-serialization-question/146313>\
**Category:** Ruby\
**Created:** [August 19, 2008, 11:42pm UTC](https://www.ruby-forum.com/t/marshal-serialization-question/146313 "2008-08-19T23:42:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [August 19, 2008, 11:42pm UTC](https://www.ruby-forum.com/t/marshal-serialization-question/146313/1 "2008-08-19T23:42:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [August 20, 2008, 7:30am UTC](https://www.ruby-forum.com/t/marshal-serialization-question/146313/2 "2008-08-20T07:30:30Z")

</div>

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… 🙂

Kind regards

robert
