- Joined
- Mar 2, 2012
- Messages
- 404
- Reaction score
- 217
- First Language
- English
- Primarily Uses
@another_fen - Yes and no. Based on my tests, for objects without a custom marshal_dump defined, it appears the order of serialization is based on the creation order of the instance variables the very first time they were created within any given class during this run. This also applies to objects reconstituted with Marshal.load() - if this was the first time certain instance variables were created, they will be "remembered" by Marshal for this run. Therefore, even if you load two objects from files from runtimes that had a different instance variable creation order (and therefore a different serialization order), the string returned by Marshal.dump() for both objects will be the same if both original objects had the same attributes, regardless of order.
If you want things to be serialized and loaded in a specific, non changing order, you can define your own marshal_dump and marshal_load instance methods, but this shouldn't be necessary unless you need Marshal support for a class that doesn't have it by default or you need to analyze the byte stream yourself.
@shaz
It should be also be for this method that a non-existent instance variable and nil value for a variable have two different serialization values, so omitting variables will cause a different serialization output even though the "value" of a non initialized instance variable is still nil. But since you said you weren't too concerned with lazy evaluation, this probably won't be an issue either.
If you want things to be serialized and loaded in a specific, non changing order, you can define your own marshal_dump and marshal_load instance methods, but this shouldn't be necessary unless you need Marshal support for a class that doesn't have it by default or you need to analyze the byte stream yourself.
@shaz
It should be also be for this method that a non-existent instance variable and nil value for a variable have two different serialization values, so omitting variables will cause a different serialization output even though the "value" of a non initialized instance variable is still nil. But since you said you weren't too concerned with lazy evaluation, this probably won't be an issue either.

