newby question

Discussion in 'Ruby' started by Alfonso, Nov 12, 2006.

  1. Alfonso

    Alfonso Guest

    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
    Alfonso, Nov 12, 2006
    #1
    1. Advertising

  2. On 11/12/06, Alfonso <> 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
    Patrick Hurley, Nov 12, 2006
    #2
    1. Advertising

  3. --------------enig3C92BCECC5B174C5752E94E5
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable

    Patrick Hurley wrote:
    > On 11/12/06, Alfonso <> 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 n=

    ew
    >> object like with ::new or .new. Could anyone explain that?

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


    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=
    =2E

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

    David Vallner


    --------------enig3C92BCECC5B174C5752E94E5
    Content-Type: application/pgp-signature; name="signature.asc"
    Content-Description: OpenPGP digital signature
    Content-Disposition: attachment; filename="signature.asc"

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.5 (MingW32)

    iD8DBQFFV1hyy6MhrS8astoRAvg7AKCAizjZCNJkTkxJEU+owqfQ4je7pgCdE+RG
    S61Dnz1MP1zmZrZ4ftX/cw0=
    =SdCi
    -----END PGP SIGNATURE-----

    --------------enig3C92BCECC5B174C5752E94E5--
    David Vallner, Nov 12, 2006
    #3
  4. Alfonso

    Alfonso Guest

    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
    Alfonso, Nov 13, 2006
    #4
  5. Alfonso

    Guest

    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

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermann W Ehlers

    Newby question

    Hermann W Ehlers, May 2, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    705
    Matt Berther
    May 5, 2004
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    ASP.NET easy newby question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    474
    Kevin Spencer
    Nov 23, 2004
  3. John Baker
    Replies:
    3
    Views:
    305
    Kevin Spencer
    Feb 8, 2005
  4. John Baker

    Rephrase of Newby Question!

    John Baker, Feb 8, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    561
    Michael C#
    Feb 9, 2005
  5. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    646
    Iain Norman
    Feb 16, 2005
Loading...

Share This Page