Forum: Ruby on Rails yaml: custom saving and loading of specific classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171c44a0c5fe6f202212984f02cf35a2?d=identicon&s=25 Bob Jones (bob84123)
on 2006-01-12 05:07
I'm trying to use ruby's yaml library to serialise and deserialise some
legacy classes.  Simply adding a to_yaml_properties() method isn't
sufficient as special methods need to be called to get and set the
properties (they're not stored simply in instance variables that I can
access), and I don't want to change the class any more than I have to.
Can anyone offer any pointers on how to get some custom code executed
when an instance of such a class is serialised and deserialised?  What
I'd like to do is, when I call YAML.dump(), and it sees an instance of
the legacy class, to convert it into some data structure and dump that,
and do the reverse on YAML.load().  I'm guessing I can do part of this
with the to_yaml() function, but I haven't been able to find an adequate
reference anywhere.  I'd really appreciate any help anyone could give
me.  Thanks.
This topic is locked and can not be replied to.