2010-07-21 123 views
6

昨天,我發現在RSpec下面的代碼:在Class中Class Class <:: OtherClassName是做什麼的?

class OptionParser < ::OptionParser 

這是什麼呢?這和class OptionParser < NameSpace::OptionParser有什麼區別?運行時

class C 
    def initialize 
    puts "At top level" 
    end 
end 

module M 
    class C 
    def initialize 
     puts "In module M" 
    end 
    end 

    class P < C 
    def initialize 
     super 
    end 
    end 

    class Q < ::C 
    def initialize 
     super 
    end 
    end 
end 

M::P.new 
M::Q.new 

主要生產:

回答

8

一個可運行的例子可能更好地解釋這個想法

In module M 
At top level 
+0

謝謝。 只要讓我確認我的理解是否正確。在我的例子中,OptionParser在稱爲optparse的標準庫中引用了OptionParser嗎?確切地說, – suzukimilanpaak 2010-07-22 09:11:33

+0

。在你的例子中':: OptionParser'指的是標準庫類 – bjg 2010-07-22 09:21:35

相關問題