From: why t. l. s. <yam...@wh...> - 2002-08-19 05:53:22
|
Brian Ingerson (in...@tt...) wrote: > It's interesting how you two both have fancy loaders and simple dumpers. > There's something asymetrical about that. I like: > > stream = dump(list_of_objects) > list_of_objects = load(stream) > > Nice symetry. I guess the Perl language make that more natural since it > supports lists. I can say for sure that Perl helped make the decision that > YAML documents would be completely independent of each other. > > I guess I'd want to have that same symetry on an iterative interface. My feelings exactly. I would like to work toward symmetry with each of the three techniques for Ruby: 1. Simple single-document, single-object dump'n'load: stream = YAML::dump( obj ) obj = YAML::load( stream ) 2. Multi-document dump'n'load: # where 'ydoc' is a YAML::Document object stream = ydoc.dump ydoc = YAML::load_document( stream ) 3. Iterative is currently read-only but I'd like to make it so you could iterate through each object and provide a means for providing an output stream so that any object returned from the block would be written to the output. In other words, to half all the salaries in the employee list: emplist = YAML::Stream.new( File.open( 'EMPLOYEES.yml' ) ) emplist2 = YAML::Stream.new( File.open( 'EMPLOYEES.yml~' ) ) emplist.each_output_to( emplist2 ) { |e| e['salary'] /= 2 } I have some problems with my Document class, as it's actually a class that contains many YAML documents. The problem is that I think most people think of a Stream as some form of IO (thanks to streaming audio or the like) and I don't want to confuse users. Any ideas? _why |