Created
February 12, 2013 20:15
-
-
Save bradland/4772990 to your computer and use it in GitHub Desktop.
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' | |
case RUBY_VERSION[0,3] | |
when "1.9" | |
YAML::ENGINE.yamler = 'syck' | |
yaml_engine = YAML::ENGINE.yamler | |
when "1.8" | |
yaml_engine = 'syck' | |
end | |
puts %[ | |
Let's see if we can serialize arbitrary objects with YAML | |
We're using: | |
Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} | |
#{yaml_engine} YAML engine | |
] | |
# Create some arbitrary object that we'll try to serialize | |
class Blox | |
attr_accessor :colors, :height, :width, :meta | |
end | |
blox = Blox.new | |
blox.colors = %w[red green blue] | |
blox.height = "10" | |
blox.width = "10" | |
blox.meta = {:owner => "John Doe", :return_to => "Central storage"} | |
puts "=== Begin YAML.dump ===\n\n" | |
puts YAML.dump(blox) | |
puts %[ | |
===End YAML.dump=== | |
If you saw the object output above, your YAML engine is capable of serializing arbitrary objects. | |
] |
Author
bradland
commented
Feb 12, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment