[#407] New feature for Ruby? — Clemens.Hintze@...

Hi all,

27 messages 1999/07/01
[#413] Re: New feature for Ruby? — matz@... (Yukihiro Matsumoto) 1999/07/01

Hi Clemens,

[#416] Re: New feature for Ruby? — Clemens Hintze <c.hintze@...> 1999/07/01

On Thu, 01 Jul 1999, Yukihiro Matsumoto wrote:

[#418] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/01

Hi

[#426] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/02

Hi,

[#440] Now another totally different ;-) — Clemens Hintze <c.hintze@...>

Hi,

21 messages 1999/07/09
[#441] Re: Now another totally different ;-) — matz@... (Yukihiro Matsumoto) 1999/07/09

Hi,

[#442] Re: Now another totally different ;-) — Clemens Hintze <c.hintze@...> 1999/07/09

On Fri, 09 Jul 1999, you wrote:

[#443] — Michael Hohn <hohn@...>

Hello,

26 messages 1999/07/09
[#444] interactive ruby, debugger — gotoken@... (GOTO Kentaro) 1999/07/09

Hi Michael,

[ruby-talk:00410] Re: open without variables and implicit closing

From: matz@... (Yukihiro Matsumoto)
Date: 1999-07-01 07:21:27 UTC
List: ruby-talk #410
Hi,

In message "[ruby-talk:00409] open without variables and implicit closing"
    on 99/07/01, Julian R Fondren <julian@cartotech.com> writes:

|If I use File.open without saving its return to a file, how can I or do I
|even need to close the file? That is: with
|``File.open('file', 'r').each{|l| print l}'' where all I'd otherwise want
|to is close the file, could I just not bother with this at all and know
|that the file had been closed?

The unreferenced file will be closed on next GC.  So, you can forget
about it unless you require immediate close/flush of the file.

If you need immediate close, you can do either:

(a)
        f = File.open('file', 'r')
        begin
          f.each{|l| print l}
        ensure
          f.close
        end

(b)
        File.open('file', 'r') do |f|
          f.each{|l| print l}
        end

(c)
        File.foreach('file', 'r'){|l| print l}

Hope this helps.
                                                matz.

In This Thread