We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

chrisaiv on 10/21/07


Tagged

ruby yaml


Versions (?)


Converting an array into YAML, Loading YAML into an array


Published in: Ruby 


  1. #A. Import the YAML Library
  2. require 'yaml'
  3. #B. Create an array
  4. names = %w[chris sandy josie billy suzie]
  5.  
  6. #Example 1 : Converting an array into YAML using: to_yaml
  7. yaml_example1 = names.to_yaml
  8. puts yaml_example1
  9.  
  10. #Example 2: Converting an array into YAML using: dump()
  11. yaml_example2 = YAML::dump(names)
  12. puts yaml_example2
  13.  
  14. #Example 3: Loading YAML back into an array using: load()
  15. array_example = YAML::load(yamloutput2)
  16. puts array_example

Report this snippet 

You need to login to post a comment.