[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

newby question

Alfonso

11/12/2006 12:57:00 PM

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...

4 Answers

Patrick Hurley

11/12/2006 1:36:00 PM

0

On 11/12/06, Alfonso <euoar@yahoo.es> 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

David Vallner

11/12/2006 5:22:00 PM

0

Patrick Hurley wrote:
> On 11/12/06, Alfonso <euoar@yahoo.es> 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.
>

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 Vallner

Alfonso

11/13/2006 10:45:00 AM

0

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...

dblack

11/13/2006 1:00:00 PM

0