11

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?

jigfox
  • 17,756
  • 3
  • 56
  • 73
Autodidact
  • 9,671
  • 15
  • 67
  • 111
  • possible duplicate of [What does class ClassName < ::OtherClassName do in Ruby?](http://StackOverflow.Com/questions/3302062/) and [What does ::MyClass Ruby scope operator do?](http://StackOverflow.Com/questions/3597096/) and probably others. – Jörg W Mittag Sep 08 '10 at 11:11
  • http://stackoverflow.com/questions/3597096/what-does-myclass-ruby-scope-operator-do – ab217 Sep 08 '10 at 10:38

1 Answers1

23

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
einarmagnus
  • 3,427
  • 1
  • 20
  • 31