From: Hal Fulton Date: 2004-03-30T03:15:08+09:00 Subject: Re: YAML and initializers why the lucky stiff wrote: >> 1. Have you given any thought to preserving comments in yaml files? >> E.g., I read in an entire file, modify some stuff, and write it out >> again -- any practical way to keep the comments? > > Okay, yeah. It's one of those things I'd like to have, but there hasn't > been a big demand for it. Truly: I'm not too excited about coding it > in. But I could really use it as well. I understand about not looking forward to coding it. I've been trying to figure out ways to approach it, and I fear it might not be practical at all in the general case. I considered a scheme where I did a to_yaml *twice*, storing the yaml in a string. This seemed fruitless. I thought of a template kind of thing, where objects would simply have their yaml stuck into the text. This also hurts my head. Then I started thinking of the potential difficulties. Suppose you load 100 objects, and then dump 101. That seems doable; you just stick the last one on the end. But what if you try to put a new object in the middle? How do you associate comments with yaml lines so that they can be kept together correctly? How does it even 'know' that a particular object goes with a particular chunk of text? Here's a thought. What if you attached singleton methods to each object that had comments, like #pre_yaml and #post_yaml? These would return the comment block before and after (whatever that means) the yaml code. There could also be a hash or something that associated data item names with their trailing comments. But this is sheer speculation. Cheers, Hal