Posted By

chrisaiv on 10/21/07


Tagged

ruby yaml


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


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.