2012-12-17 45 views

回答

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開頭的函數。