簡體   English   中英

ruby 2.2,如何顯示文件的當前內容?

[英]ruby 2.2 , how to display the current content of the file?

在紅寶石中2.2。 腳本,我正在編寫一個xml文件

@filehandle << '<plist version="1.0">'
...
@filehandle << "\n<#{element_name}>"
..

在調試過程中,我想顯示當前內容,因為它尚未關閉,但僅緩存...,如何獲取它? 謝謝你的建議

byebug 
@filehandle.class
File
@filehandle
#<File:./AlbumData-new.xml>

您可以執行這些調用以顯示內容(我假設已打開文件進行讀寫,即mode為r+w+a+

@filehandle.flush # Make sure everything is written to disk
@filehandle.seek(0) # So we can read from the beginning
@filehandle.read # Read everything

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM