From: Hal Fulton Date: 2004-03-29T20:30:57+09:00 Subject: Re: YAML and initializers why the lucky stiff wrote: > Good discussion, Hal. I've been really rethinking the YAML+Ruby typing > mechanism, so this is a perfect time for this. Right on. Good, I have some other random thoughts below. Thanks for replying... > In the case of the above constructor, it would be impossible for YAML to > know in what order to pass the three parameters and I don't have any > ideas for making the YAML loader work with the constructor. Right, I was thinking of some heavyweight solution in which we passed symbols to a YAML.construct or some such. Silliness basically. > I think the best solution for this would be akin to > Object#initialize_copy. In fact, it seems like YAML could call > Object#initialize_copy with the new object, should an > Object#initialize_copy method exist. Yeh? Very good idea, yes. I see no drawbacks there so far. Wish I had thought of that. I made do with a #defaults method that did an ||= on each nil value. Cleaned up #initialize a bit, which now calls it. I was seriously thinking of an RCR to allow things like: def initialize(@alpha,@beta,@gamma=5) # Nothing else needed here end But I think Matz rejected a similar idea 2-3 years ago. > Yes, you can also do this with a typing callback: [snip] Ah, cool, yes. Other questions... 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? 2. I wish for a little more control over formatting. Possible? a. Specify order of fields instead of alphabetic b. Align field names and data in a "prettyprinted" way Thanks for all your hard work... Hal