2009-06-04 4 views
1

私はRailsでファイルストリームが開いているかどうかを確認することはできますか?

begin 
    f = File.new(contacts_file_path, "wb") 
    f.write params[:uploaded_file].read 
rescue 
    #error 
ensure 
    if f.open? then f.close end 
end 

しかしf.openたい

f = File.new(contacts_file_path, "wb") 
f.write params[:uploaded_file].read 
f.close 

がありますか?関数ではなく、私はAPIのドキュメントを見つけることができません。何か案は?

答えて

6
f.close unless f.closed? 
関連する問題