What is the right command for file cose

Hi All,

I want to know, which is the right command to close the file, f.close
is the right command, or any, please let me know

On 10/15/07, Vidya V. [email protected] wrote:

Hi All,

I want to know, which is the right command to close the file, f.close
is the right command, or any, please let me know

Assuming f is a File, yes f.close will close it.

On the other hand, if possible, it’s better to use the form of
File.open which takes a block

File.open(file_path) do | f |
# code that works with the file referenced by f
end

This automatically closes the file when the block finishes.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On 10/15/07, Vidya V. [email protected] wrote:

Hi All,

I want to know, which is the right command to close the file, f.close
is the right command, or any, please let me know

Posted via http://www.ruby-forum.com/.


Cheers!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs