[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Yaml append and query

Charles L. Snyder

6/12/2006 3:37:00 PM

Hi

I have a couple of quick YAML.rb questions (documentation is a little
sparse)

lets say i create a .yaml file (like the example below):

require 'yaml'
my_struct = Struct::new( "Books", :title, :publisher, :year)
w = (my_struct.new("davinci code", "doubleday", 2005))
open("my_db.yaml","w"){|e| e << w.to_yaml}

Now, if the my_db.yaml file was big, say > 1000 entries:

1. I know how to read in the .yaml file to ruby, add data (eg another
book), and then write a new .yaml file out - but, how do i just append
a new entry to the .yaml file without reading in the whole file and
writing out the entire new file (how to append an entry)?

2. Is there a way to directly query the .yaml file:
"find all books published after 1998 by doubleday?
Again, without reading the whole thing into an array of hashes, etc..

Thanks (again)

CLS