我試圖找到File.open()
是如何實現的,但我無法找到它,而在我從https://github.com/ruby/ruby在Ruby中如何實現File.open?
0
A
回答
0
沒有File::open
,它是從IO
繼承。所以,你需要尋找IO::open
。
一般來說,我建議使用Rubinius源代碼。它比YARV的源代碼組織得更好,文檔也更好,最重要的是:它主要是用Ruby編寫的,而在YARV中,整個語言,整個核心庫和標準庫的重要部分都用C編寫。
這就是說,the implementation of IO::open
is completely and utterly boring。它只是做了明顯的事情:
def self.open(*args)
io = new(*args)
return io unless block_given?
begin
yield io
ensure
begin
io.close unless io.closed?
rescue StandardError
# nothing, just swallow them.
end
end
end
1
得到的File
類是C模塊中,並不是Ruby的一個代碼grepping左右。所以,你不會找到它的Ruby代碼。
看起來像它住在根文件夾中的file.c
。該模塊包含IO
模塊,該模塊是另一個C模塊,位於io.c
中的相同位置。在那裏尋找名字以rb_file_open
開頭的函數。
相關問題
- 1. File.Open encoding呈現HTML實體
- 2. File.open和Ruby 1.8.7中的塊
- 3. 我如何在Ruby中實現事實?
- 4. 如何在ruby中實現抽象類?
- 5. 如何在Ruby中實現INSTREAM協議?
- 6. 如何在Ruby中實現進度條?
- 7. 如何在Ruby中實現查找類?
- 8. 如何在Ruby Net :: HTTP中實現Cookie
- 9. 如何在Ruby中實現1.day.ago
- 10. 如何在Ruby中實現RESTful服務
- 11. 如何實現Object.try!在Ruby on Rails中?
- 12. 如何在ruby中實現argmax?
- 13. 如何在Ruby中實現枚舉器?
- 14. 如何在Ruby中實現注入?
- 15. 如何在Ruby中實現「回調」?
- 16. 錯誤使用Ruby和File.open
- 17. Cloudfoundry [Cloudfoundry] File.open ruby rails resque class
- 18. 如何使用File.Open在ruby中打開存儲在變量中的文件?
- 19. 在ruby中實現iota
- 20. 在Ruby中實現`call_user_func_array`
- 21. 如何在File.open塊中存儲file.read?
- 22. Ruby的File.open奇怪的行爲
- 23. Ruby的File.open和f.close的需要
- 24. 如何使用Ruby的File.open命令編輯* nix系統文件?
- 25. 如何在Ruby中的方法中實現for循環
- 26. 如何在Delphi中實現XIRR實現?
- 27. Ruby http-2實現:eof如何工作?
- 28. 如何實現一些Ruby概念?
- 29. 在網站上實現Ruby
- 30. Ruby on Rails:如何在我的webapp中實現快捷鍵?