Yaml Serialization Example


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. require "yaml"
  2.  
  3. class Hello
  4. attr_reader :monkey
  5. def hoho
  6. @monkey = "bob"
  7. end
  8. end
  9.  
  10. a = Hello.new
  11. a.hoho
  12.  
  13. puts a.to_yaml.inspect
  14.  
  15. b = Hello.new
  16.  
  17. puts b.to_yaml.inspect
  18.  
  19. aa = "--- !ruby/object:Hello nmonkey: bobn"
  20. bb = "--- !ruby/object:Hello {}nn"
  21.  
  22. aaa = YAML::load(aa)
  23. bbb = YAML::load(bb)
  24.  
  25. puts aaa.inspect
  26. puts bbb.inspect
  27.  
  28. puts aaa.monkey
  29. puts bbb.monkey

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.