Created
December 12, 2012 19:35
-
-
Save rewinfrey/4270841 to your computer and use it in GitHub Desktop.
A simple example showing how attributes of objects that are objects are also serialized when we serialize the base object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
class RetainAttributeOfToYaml | |
attr_accessor :name | |
def initialize(name) | |
@name = "Hi, my name is #{name}." | |
end | |
end | |
class ToYaml | |
attr_accessor :attribute_to_retain | |
def initialize(attribute) | |
@attribute_to_retain = attribute | |
end | |
end | |
attribute1 = RetainAttributeOfToYaml.new("Schrodinger") | |
attribute2 = RetainAttributeOfToYaml.new("Cat") | |
ex1 = ToYaml.new(attribute1) | |
ex2 = ToYaml.new(attribute2) | |
ex1_serialized = YAML::dump(ex1) | |
ex2_serialized = YAML::dump(ex2) | |
ex1_deserialized = YAML::load(ex1_serialized) | |
ex2_deserialized = YAML::load(ex2_serialized) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment