# Using YAML Files with comments

**URL:** <https://www.ruby-forum.com/t/using-yaml-files-with-comments/156436>\
**Category:** Ruby\
**Created:** [December 27, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/using-yaml-files-with-comments/156436 "2008-12-27T15:36:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 27, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/using-yaml-files-with-comments/156436/1 "2008-12-27T15:36:36Z")

</div>

Years ago when I started to use yaml files more heavily I also started  
to grow accustomed to the habit of commenting my yaml files - within  
that yaml file.

The question I now have is whether if it is possible to save those  
comments when saving the yaml file. To my current knowledge this is not  
possible when writing a yaml file such as:

YAML\_FILE = “/x.yml”  
File.open(YAML\_FILE, ‘w’) { |file| YAML.dump(tree.file) }

(Note, I actually assume that x.yml already exists and contains  
information, including comments.)

I think my problem is that yaml files were thought to be equivalent to  
“config files” - on Linux you often see config files which contain  
comments - however if I loose all my comments always, I really can not  
use yaml files for _all_ config files; only for those config files where  
I dont need in-file comments.
