昨天,我在
RSpec中找到了以下代码:
class OptionParser < ::OptionParser
这是做什么的?这和OptionParser类有什么区别?命名空间:: OptionParser?
解决方法@H_404_8@
一个可运行的例子可能最好地解释这个想法:
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
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