# :: without a prefix (global?)

**URL:** <https://www.ruby-forum.com/t/without-a-prefix-global/54062>\
**Category:** Ruby\
**Created:** [December 19, 2005, 6:47am UTC](https://www.ruby-forum.com/t/without-a-prefix-global/54062 "2005-12-19T06:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 19, 2005, 6:47am UTC](https://www.ruby-forum.com/t/without-a-prefix-global/54062/1 "2005-12-19T06:47:08Z")

</div>

I’ve found some cases where things don’t work correctly unless they’re  
prefixed with a :: . I’m really confused - isn’t :: used to specify the  
module (like Graphics::Circle)?

What is ::Circle? No module?!

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 19, 2005, 7:00am UTC](https://www.ruby-forum.com/t/without-a-prefix-global/54062/2 "2005-12-19T07:00:15Z")

</div>

On Dec 18, 2005, at 9:47 PM, List R. wrote:

> I’ve found some cases where things don’t work correctly unless they’re  
> prefixed with a :: . I’m really confused - isn’t :: used to  
> specify the  
> module (like Graphics::Circle)?
> 
> What is ::Circle? No module?!

The constant Circle at toplevel.

$ irb  
irb(main):001:0\> A = 1  
=\> 1  
irb(main):002:0\> module M  
irb(main):003:1\> A = 2  
irb(main):004:1\> puts A  
irb(main):005:1\> puts ::A  
irb(main):006:1\> end  
2  
1  
=\> nil

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 19, 2005, 2:38pm UTC](https://www.ruby-forum.com/t/without-a-prefix-global/54062/3 "2005-12-19T14:38:28Z")

</div>

List R. wrote:

> I’ve found some cases where things don’t work correctly unless they’re  
> prefixed with a :: . I’m really confused - isn’t :: used to specify the  
> module (like Graphics::Circle)?
> 
> What is ::Circle? No module?!

`::’ will take you to the top level.

Bar = “::Bar”

module Foo  
Bar = “Foo::Bar”

```
 def self.bur
   puts Bar => "Foo::Bar"
   puts ::Bar => "::Bar"
 end

```

end

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 20, 2005, 4:15am UTC](https://www.ruby-forum.com/t/without-a-prefix-global/54062/4 "2005-12-20T04:15:54Z")

</div>

Thanks.

Is there any case where you will use :: when you have not defined a  
class with the same name in the local module?

I was working on a project where I could not access a certain class  
within a module without prefixing it with ::, yet I had never (to my  
knowledge) redefined it.

(FYI, in a Rails ActiveController, you can catch  
::ActiveController::NameOfExceptionClass, but you need the :: …  
weird!)

Eric H. wrote:

> On Dec 18, 2005, at 9:47 PM, List R. wrote:
> 
> > I’ve found some cases where things don’t work correctly unless they’re  
> > prefixed with a :: . I’m really confused - isn’t :: used to  
> > specify the  
> > module (like Graphics::Circle)?
> > 
> > What is ::Circle? No module?!
> 
> The constant Circle at toplevel.
> 
> $ irb  
> irb(main):001:0\> A = 1  
> =\> 1  
> irb(main):002:0\> module M  
> irb(main):003:1\> A = 2  
> irb(main):004:1\> puts A  
> irb(main):005:1\> puts ::A  
> irb(main):006:1\> end  
> 2  
> 1  
> =\> nil
> 
> –  
> Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
