From: Robert Klemme Date: 2012-01-20T19:55:19+09:00 Subject: Re: Beginner Questions On Thu, Jan 19, 2012 at 11:32 PM, Ryan Davis wrote: > > On Jan 19, 2012, at 14:22 , Robert Klemme wrote: > >> Another remark: $dives.to_yaml(f) is potentially more efficient since >> output is directly written to the stream whereas the form with #write >> first creates the complete string in memory before writing it. > > Huh. I didn't know you could do that. Normally I use YAML.dump and pass the IO in. Even better! That way you can easily exchange persistence with Marshal. irb(main):004:0> data = {:now => Time.now} => {:now=>2012-01-20 11:53:17 +0100} irb(main):005:0> f="x" => "x" irb(main):006:0> [Marshal, YAML].each do |perst| irb(main):007:1* File.open(f,'wb'){|io| perst.dump(data, io)} irb(main):008:1> p File.open(f,'rb'){|io| perst.load(io)} irb(main):009:1> end {:now=>2012-01-20 11:53:17 +0100} {:now=>2012-01-20 11:53:17 +0100} => [Marshal, Psych] :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/