in ruby, :: namespaces the module and class. But I often see :: at the beginning of the class name like the following:
#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 that :: stands for if its in the beginning?
It is to resolve against the global scope instead of the local.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With