Working with Hashes and YAML in Ruby
View as text
# assuming this yaml file in the same folder...
#
# first:
# name: foo
# next:
# name: hello world
require 'rubygems'
require 'yaml'
root_path = File.dirname(__FILE__)
c = YAML::load(File.open("#{root_path}/config.yml"))
puts c.inspect
puts c["first"]["name"]
puts c["next"]["name"]
# write this out to a new file
File.open ("new.yaml", "w") do |f|
f << c.to_yaml
end
