July 2011
Intermediate to advanced
400 pages
8h 46m
English
As with YAML serialization, it is possible to limit the variables that are saved when serializing using Marshal. In YAML, you did this by writing a method called to_yaml_properties. With Marshal, you need to write a method named marshal_dump. In the code of this method you should create an array containing the actual variables to be saved (in YAML, you created an array of strings containing the variable names).
This is an example:
def marshal_dump
[@variable_a, @variable_b]
endAnother difference is that, with YAML, you were able simply to load the data in order to re-create an object. With Marshal, you need to add a special method called marshal_load to which any loaded data is passed as an argument. This will be invoked ...
Read now
Unlock full access