# Ruby Syntax - One::Two

**URL:** <https://www.ruby-forum.com/t/ruby-syntax-one-two/85783>\
**Category:** Ruby\
**Created:** [February 16, 2007, 9:16am UTC](https://www.ruby-forum.com/t/ruby-syntax-one-two/85783 "2007-02-16T09:16:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 16, 2007, 9:16am UTC](https://www.ruby-forum.com/t/ruby-syntax-one-two/85783/1 "2007-02-16T09:16:03Z")

</div>

I’m a newcomer to ruby and there’s this little something I don’t  
really understand:

class One::Two  
…  
end

Class One::Three  
…  
end

On this example, what does “::” mean? If understand correctly it’s  
just sort of a naming convention to imply that both the Two and Three  
classes belong to the same “group”, as in Net::HTTP and Net::FTP.  
So, in essence Two and Three are completely unrelated, and I’d not  
even need to have a class named One for it to work, is that right?

If not, please tell me, what exactly is the purpose of “::” on class  
names?

Thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 16, 2007, 11:27am UTC](https://www.ruby-forum.com/t/ruby-syntax-one-two/85783/2 "2007-02-16T11:27:17Z")

</div>

Alle venerdì 16 febbraio 2007, removed\_email\_address@domain.invalid ha scritto:

> On this example, what does “::” mean? If understand correctly it’s  
> just sort of a naming convention to imply that both the Two and Three  
> classes belong to the same “group”, as in Net::HTTP and Net::FTP.  
> So, in essence Two and Three are completely unrelated, and I’d not  
> even need to have a class named One for it to work, is that right?
> 
> If not, please tell me, what exactly is the purpose of “::” on class  
> names?
> 
> Thanks

:: is the scope operator. It is used to access constants defined in a  
class or  
module. Since classes are constants, when you write class One::Two,  
you’re  
defining the class Two inside One (where One can be a class or a  
module). If  
you didn’t define One, the code class One::Two will give you a  
NameError,  
telling you that the constant One is not initialized:

> > class One::Two  
> > end  
> > NameError: uninitialized constant One  
> > from (irb):1
> 
> >

Another example of the use of :: is

puts Math::PI, which prints the value of the PI constant

> > puts Math::PI  
> > 3.14159265358979

Since PI belongs to the Math module, I couldn’t have written puts PI. In  
fact,  
this raises an exception:

> > puts PI  
> > NameError: uninitialized constant PI  
> > from (irb):5

I hope this helps.

Stefano

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 16, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/ruby-syntax-one-two/85783/3 "2007-02-16T13:15:36Z")

</div>

On Feb 16, 8:26 am, Stefano C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > If not, please tell me, what exactly is the purpose of “::” on class
> > 
> > > class One::Two
> 
> ```
> from (irb):5
> 
> ```
> 
> I hope this helps.
> 
> Stefano

I understand now, I didn’t realize “class One::Two” actually defined  
the constant Two inside One.  
Thank you!
