From: koyama Date: 2007-08-31T22:32:55+09:00 Subject: [ruby-list:43966] Re: Hashのシリアライズ xeon-koyamaです Marshal が上手く行きません。 どなたか、ご教授頂ければ助かります。 =========================================== #!/usr/bin/ruby class AAA def initialize if File.exist?("hashfile") f = File.open("hashfile", 'r') @dat = Marshal.load(@dat, f) else @dat = Hash.new @dat.store('KEY_0', '0') @dat.store('KEY_1', '1') @dat.store('KEY_2', '2') end end def readDat if !@dat.empty? @dat.each_pair { |key, value| puts "#{key}=#{value}" } end end def close Marshal.dump(@dat, open("hashfile", 'w')) end end t = AAA.new t.readDat t.close =========================================== 初回起動は、ちゃんと hashfileが保存されます 問題は、2回目起動時の hashfileの読み込み時に test.rb:8:in `load': instance of IO needed (TypeError) from test.rb:8:in `initialize' from test.rb:32:in `new' from test.rb:32 といったエラーがでます。 Hashの中身は、リテラル(String型?)なので、 hashcodeは問題ないと思いますが、 いったいどこがイケないのでしょうか