[#20036] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

16 messages 2003/04/18
[#20045] Re: Roundoff problem with Float and Marshal — nobu.nakada@... 2003/04/20

なかだです。

[#20063] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto) 2003/04/22

まつもと ゆきひろです

[#20097] jcode.rb — akira yamada / やまだあきら <akira@...>

25 messages 2003/04/26
[#20098] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/27

まつもと ゆきひろです

[#20105] Re: jcode.rb — WATANABE Hirofumi <eban@...> 2003/04/28

わたなべです。

[#20108] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/28

まつもと ゆきひろです

[ruby-dev:20112] Marshal.foreach

From: Beyond <beyond@...>
Date: 2003-04-29 04:56:21 UTC
List: ruby-dev #20112
Beyondです。

Marshalに、IO.foreach のようなモジュール関数があると便利だと思うのですが、
いかがでしょう?

たとえば、ログをファイルに追加モードで書き込んでいって、あとでまとめて解
析したいときに使います。

-----------------------------------------
def Marshal.foreach( fname )
    File.open( fname ) { | file |
        while( !file.eof )
            yield Marshal.load( file )
        end
    }
end

a = "first"
b = "second"
File.open( "a.dat", "w" ) { | file |
    Marshal.dump( a, file );
    Marshal.dump( b, file );
}

Marshal.foreach( "a.dat" ) { | obj |
    p obj
}

---------------------
Beyond



In This Thread

Prev Next