Yaml append and query

C

Charles L. Snyder

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top