Reading and Writing Configuration Files : YAML « XML « Ruby






Reading and Writing Configuration Files


require 'yaml'
configuration = { 'color' => 'blue',
                  'font' => 'new romain',
                  'font-size'  => 7 }
open('text.cfg', 'w') { |f| YAML.dump(configuration, f) }

open('text.cfg') { |f| puts f.read }

open('text.cfg') { |f| YAML.load(f) }

 








Related examples in the same category

1.YAML Demo
2.use YAML::dump to convert your Person object array into YAML data
3.Output a hash with yaml
4.Convert hash to configuration file
5.YAML for Marshaling