类ClassName <:: OtherClassName在Ruby中做什么?

昨天,我在RSpec中找到了以下代码:

class OptionParser < ::OptionParser 

这是做什么的? 这个和class OptionParser < NameSpace::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 

运行时产生:

 In module M At top level