sneJ (snej) wrote in ruby_lang,

preventing variables from being marshaled

I'm using PStore (which uses Marshal) as a quick-n-dirty way to store my app's persistent state. It worked great until I added a Socket instance variable to one of my classes. Sockets can't be marshaled (of course) so now I get an exception.

The docs say to implement _dump and _load methods to override that class's marshaling. But I'm not sure what to make them do. The best I can come up with is to implement _dump by collecting all the other ivars into an array or hash, marshaling that, and returning that string. Then _load does the opposite.

I can make that work. What concerns me is what it will do to cycles in the object graph. If this object's ivars are being marshaled separately, what happens if one of them is an object that's referred to elsewhere in the object graph? Does it get written twice, and (worse) read back in as two separate objects? In my case that would really screw up my app.

What I really want is Java's "transient" attribute...
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.