From: "Sebastjan H." Date: 2012-10-20T17:26:29+09:00 Subject: Re: database part of a desktop application unknown wrote in post #1080513: > Am 19.10.2012 23:16, schrieb Sebastjan H.: > >> File.open("all_cards.yml", "a+") {|f| YAML.dump(card, f)} >> >> This appends object after object. Here's the problem. How can I then >> access and display certain or all cards after loading the file: >> >> card_file = YAML.load_file("all_cards.yml") >> >> I've tried putsing the card_file with different parameters but I always >> get back the name of the first objec tin the storage. > > By appending, you end up with several YAML documents (or objects) > in your file. > > > You could iterate through them with: > > f = File.open('all_cards.yml') > YAML.load_documents(f) do |card| > p card > end > > > Or you could read them all at once with: > > cards = nil > File.open('all_cards.yml') do |f| > cards = YAML.load_stream(f) > end > > p cards > > >> And one last question, If I go with YAML and not YAML::Store can I >> delete certain card from the storage? > > Read in all the cards and overwrite your YAML file, leaving out the > card you want to delete. Thank you. I think I'll also look into the YAML::Store a bit more. Where would I find a complete reference for it? Ruby-doc at http://www.ruby-doc.org/stdlib-1.9.3/libdoc/yaml/rdoc/YAML/Store.html only provides basic info. Since the parent is PStore, may I just use that as a full reference? I think the confusing part in all this is my perception of the storage files related to these functionalities and their manipulation (storing and loading of objects). -- Posted via http://www.ruby-forum.com/.