Forum: Ruby Loading one YAML object at a time.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2007-03-04 20:41
(Received via mailing list)
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''testyaml','w') do |f|
  YAML.dump("string1", f)
  YAML.dump("string2", f)
end"testyaml") do |f|
  p YAML.load(f)
  p YAML.load(f)
end"testyaml") do |f|
  YAML.each_document(f) {|obj| p obj}

rick@frodo:/public/rubyscripts$ ruby multiyaml.rb

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.

Rick DeNatale

My blog on Ruby
This topic is locked and can not be replied to.