views:

59

answers:

2

Hi, 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?

+6  A: 

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
ormuriauga