What is :: sign / operator before a class name in ruby?

in ruby, :: namespaces module and class. But I often see :: at the beginning of the class name, as shown below:

#snippet of gollum gem def page_class @page_class || if superclass.respond_to?(:page_class) superclass.page_class else ::Gollum::Page end end 

What does it mean :: means if it is at the beginning?

+4
source share
1 answer

It is intended to eliminate a global scope, not a local one.

 class A def self.global? true end end module B class A def self.global? false end end def self.a puts A.global? puts ::A.global? end end B::a 

prints

 false true 
+14
source

All Articles