Guest User

Untitled

a guest
Jun 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. require "yaml"
  2. fname = "hash_output.txt"
  3. hsh = {
  4. "test" => "foo",
  5. "test2" => "foo2"
  6. }
  7.  
  8. #save to file...
  9. File.open(fname, "w"){|fo|
  10. fo << YAML.dump(hsh)
  11. }
  12.  
  13. hsh2 = {}
  14. #load from file...
  15. File.open(fname, "r"){|fo|
  16. hsh2 = YAML.load(fo)
  17. }
  18.  
  19. #test new hash...
  20. hsh2.each{|k, v|
  21. puts "#{k} => #{v}"
  22. }
Add Comment
Please, Sign In to add comment