# Newby question

**URL:** <https://www.ruby-forum.com/t/newby-question/75696>\
**Category:** Ruby\
**Created:** [November 12, 2006, 1:57pm UTC](https://www.ruby-forum.com/t/newby-question/75696 "2006-11-12T13:57:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 12, 2006, 1:57pm UTC](https://www.ruby-forum.com/t/newby-question/75696/1 "2006-11-12T13:57:43Z")

</div>

Sorry for the too elemental question (don’t know if this is the right  
place to make questions like this) I just have started with ruby, and  
don’t understand the difference “::” “.” I have read that :: is for  
accessing constants, but then I see, that, for example, I can make a new  
object like with ::new or .new. Could anyone explain that?

Thank you very much.

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 12, 2006, 2:37pm UTC](https://www.ruby-forum.com/t/newby-question/75696/2 "2006-11-12T14:37:52Z")

</div>

On 11/12/06, Alfonso [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry for the too elemental question (don’t know if this is the right  
> place to make questions like this) I just have started with ruby, and  
> don’t understand the difference “::” “.” I have read that :: is for  
> accessing constants, but then I see, that, for example, I can make a new  
> object like with ::new or .new. Could anyone explain that?

There is some overlap, but in general usage, use :: to access names  
that are scoped within modules and use . to send messages (call)  
methods.

At least while you are getting started, this is the easiest thing to  
remember.  
pth

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 12, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/newby-question/75696/3 "2006-11-12T18:22:29Z")

</div>

Patrick H. wrote:

> 

To be precise, :: and . are completely equivalent operators to call  
methods of an object. I think (not really sure) that an older version of  
Ruby only let you use :: for class methods, but that’s no longer the  
case.

Only :: can be used for constant lookup; it’s idiomatic to use . for any  
method calls, as Patrick says.

David V.

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 13, 2006, 2:00pm UTC](https://www.ruby-forum.com/t/newby-question/75696/4 "2006-11-13T14:00:47Z")

</div>

Hi –

On Mon, 13 Nov 2006, Alfonso wrote:

> Thank you very much for your answers. So if I have understood right:
> 
> - “::” constants, and module methods
> - “.” methods
> 
> I also have read today in “ruby in a nutshell”, that “::” is preferred also  
> with class methods (but the war wroten in 2001, so it could be a bit  
> outdated).

My recommendation is:

“::” for constant paths  
“.” for method calls

I don’t think there’s any reason to use :: for method calls just  
because the receiver is a class or module. It just adds an  
unnecessary special case.

David

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 13, 2006, 11:46am UTC](https://www.ruby-forum.com/t/newby-question/75696/5 "2006-11-13T11:46:33Z")

</div>

Thank you very much for your answers. So if I have understood right:

- “::” constants, and module methods
- “.” methods

I also have read today in “ruby in a nutshell”, that “::” is preferred  
also with class methods (but the war wroten in 2001, so it could be a  
bit outdated).

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)
