What does :: mean at the beginning?

Hi, looking at a Ruby code I’ve found this:

repo = ::Logging::Repository.instance

What does the first :: mean?

Thanks.

It’s an “ensure you’re pulling from the top level”. Works exactly the
same as in C++

Jason

On Aug 21, 2008, at 2:41 PM, Iñaki Baz C. wrote:

Hi, looking at a Ruby code I’ve found this:

repo = ::Logging::Repository.instance

What does the first :: mean?

Thanks.

start a the ‘top’ namespace

class A
end

module M
class A
end

p ::A   # the top level one, not the normally scoped one

end

a @ http://codeforpeople.com/

El Jueves, 21 de Agosto de 2008, Jason R.
escribió:> It’s an “ensure you’re pulling from the top level”. Works exactly the

same as in C++

Let me be sure:

module A
CONS = “AAA”
module B
CONS = “BBB”
end
end

module A
module B
puts ::a::CONS
end
end

=> AAA

Is it?

Thanks a lot.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs