本文簡要介紹ruby語言中 EOFError類
的用法。
到達文件末尾時由一些 IO
操作引發。許多 IO
方法以兩種形式存在,
一個在到達文件末尾時返回 nil
,另一個引發 EOFError
。
EOFError
是 IOError
的子類。
file = File.open("/etc/hosts")
file.read
file.gets #=> nil
file.readline #=> EOFError: end of file reached
相關用法
- Ruby ERB.location=用法及代碼示例
- Ruby Enumerable.any?用法及代碼示例
- Ruby Enumerable min_by()用法及代碼示例
- Ruby Enumerable each_witth_object()用法及代碼示例
- Ruby ErrorHighlight.spot用法及代碼示例
- Ruby Enumerable.slice_before用法及代碼示例
- Ruby Enumerable each_cons()用法及代碼示例
- Ruby Enumerator each_with_index用法及代碼示例
- Ruby Encoding.compatible?用法及代碼示例
- Ruby Enumerable.uniq用法及代碼示例
- Ruby Enumerator each_with_object用法及代碼示例
- Ruby ERBIO類用法及代碼示例
- Ruby ENV.empty?用法及代碼示例
- Ruby Enumerable uniq()用法及代碼示例
- Ruby Enumerable.find_all用法及代碼示例
- Ruby Enumerator.peek_values用法及代碼示例
- Ruby Enumerable.max用法及代碼示例
- Ruby Enumerable.map用法及代碼示例
- Ruby Enumerable min()用法及代碼示例
- Ruby Enumerable.min_by用法及代碼示例
- Ruby Enumerable.find_index用法及代碼示例
- Ruby Enumerator類用法及代碼示例
- Ruby Enumerable find_index()用法及代碼示例
- Ruby ENV.delete_if用法及代碼示例
- Ruby Enumerable find_all()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 EOFError類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。