This sets the ivars before calling initialize, which feels wrong. But
Data doesn't give us any mechanism for setting the members other than 1)
initialize, or 2) drop down into the C API. Since initialize freezes
the object, we need to set the ivars before that. I think this is a
reasonable compromise—if users need better handling, they can implement
their own encode_with and init_with. But it will lead to unhappy
surprises for some users.
Alternatively, we could use the C API, similarly to Marshal. Psych is
already using the C API for path2class and build_exception. This would
be the least surprising behavior for users, I think.
Add support for Data objects with ivars
This sets the ivars before calling initialize, which feels wrong. But
Data doesn't give us any mechanism for setting the members other than 1)
initialize, or 2) drop down into the C API. Since initialize freezes
the object, we need to set the ivars before that. I think this is a
reasonable compromise—if users need better handling, they can implement
their own
encode_with
andinit_with
. But it will lead to unhappysurprises for some users.
Alternatively, we could use the C API, similarly to Marshal. Psych is
already using the C API for path2class and build_exception. This would
be the least surprising behavior for users, I think.