rails/rails — pull request #11193 by ryan-endacott (2013-06-30 07:04:46+00:00)
Title: Instance variables are now serialized to YAML

Fixes #11035
Instance variables were not being serialized to YAML.
Ex:
```ruby
YAML.load(Topic.new.to_yaml).new_record?
```
This previously returned false, and it now correctly returns true.

To solve this issue, it looked like the instance variables could either be saved or recalculated. Some (`@readonly`) can't always be recalculated, so they would be lost. So I opted to save the instance variables.

`Core#encode_with` now saves instance variables (except for `@attributes` and `@column_hash`, because I believe those were already handled). `Core#init_with` was changed to check if `coder['instance_variables']` exists, and loads the instance variables if it does. I did this to keep backwards compatibility, because it looks like `init_with` is used for more than just deserializing from YAML. This is my first attempt at a pull request, so I apologize if anything is incorrect. I also feel like there may be a more elegant solution, but I'm not sure how much `Persistence#instantiate` depends on the current definition of `init_with` so I didn't make any breaking changes. Please let me know if there's a better way, and I'll get to implementing it! Thanks! :-)