2009-06-04 41 views
1

我已經是否有可能檢查文件流是否在Rails中打開?

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

我想

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?不是一個函數,我找不到任何api文檔。有任何想法嗎?

回答

6
f.close unless f.closed?