Loading one YAML object at a time.

R

Rick DeNatale

I'd like to write a series of YAMLized objects to a file, then read
them in one by one.

I tried this test:
rick@frodo:/public/rubyscripts$ cat multiyaml.rb
require 'yaml'

File.open('testyaml','w') do |f|
YAML.dump("string1", f)
YAML.dump("string2", f)
end

File.open("testyaml") do |f|
p YAML.load(f)
p YAML.load(f)
end

File.open("testyaml") do |f|
YAML.each_document(f) {|obj| p obj}
end

rick@frodo:/public/rubyscripts$ ruby multiyaml.rb
"string1"
false
"string1"
"string2"


It looks like YAML.load isn't properly leaving the file positioned to
read the second object. Is this a bug?

YAML.each_document seems to do the right thing, but I'm concerned
about the memory overhead for large files.
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top