Meaning of ::

Discussion in 'Ruby' started by Guido Granobles, Nov 7, 2010.

  1. Hi!.. I'm very new with Ruby and I wold like to know what does it mean
    the four points when I am doing inheritance. Like:
    Code:
    class1::base
    
    I know that it represents a constant but how I should interpret that.

    --
    Posted via http://www.ruby-forum.com/.
     
    Guido Granobles, Nov 7, 2010
    #1
    1. Advertising

  2. Guido Granobles

    Scott Gonyea Guest

    Class and Module names must be in their "proper case" form. So, =
    "Class1::Base". Constants are in all caps, while methods and variable =
    names are lower case.

    The :: operator is used to delimit namespace. Without using namespaces =
    for your library, everyone who wanted to call their class "Base" would =
    collide with each other. You'd get some very unpredictable behavior.

    Besides preventing namespace collisions, it helps you to organize and =
    describe your objects.

    Scott

    On Nov 6, 2010, at 8:11 PM, Guido Granobles wrote:

    > Hi!.. I'm very new with Ruby and I wold like to know what does it mean
    > the four points when I am doing inheritance. Like:
    >
    Code:
    > class1::base
    > 
    > I know that it represents a constant but how I should interpret that.
    >=20
    > --=20
    > Posted via http://www.ruby-forum.com/.
    >=20
     
    Scott Gonyea, Nov 7, 2010
    #2
    1. Advertising

  3. What about code like:

    ::Digest::MD5.hexdigest "xxx"

    Why is the :: before Digest module nothing?

    On Nov 7, 2010, at 1:29 PM, Scott Gonyea wrote:

    > Class and Module names must be in their "proper case" form. So, =

    "Class1::Base". Constants are in all caps, while methods and variable =
    names are lower case.
    >=20
    > The :: operator is used to delimit namespace. Without using =

    namespaces for your library, everyone who wanted to call their class =
    "Base" would collide with each other. You'd get some very unpredictable =
    behavior.
    >=20
    > Besides preventing namespace collisions, it helps you to organize and =

    describe your objects.
    >=20
    > Scott
    >=20
    > On Nov 6, 2010, at 8:11 PM, Guido Granobles wrote:
    >=20
    >> Hi!.. I'm very new with Ruby and I wold like to know what does it =

    mean
    >> the four points when I am doing inheritance. Like:
    >>
    Code:
    >> class1::base
    >> 
    >> I know that it represents a constant but how I should interpret that.
    >>=20
    >> --=20
    >> Posted via http://www.ruby-forum.com/.
    >>=20

    >=20
    >=20



    Best regards,
    Zhi-Qiang Lei
     
    Zhi-Qiang Lei, Nov 7, 2010
    #3
  4. On Sun, Nov 7, 2010 at 9:37 AM, Zhi-Qiang Lei <> wrote:
    > What about code like:
    >
    > ::Digest::MD5.hexdigest "xxx"
    >
    > Why is the :: before Digest module nothing?


    That means to refer to the top most Digest constant, to avoid
    referencing the wrong one in cases like this:

    module Test
    module Digest
    # my own Digest module
    end

    class TestClass
    Digest # refers to my own module
    ::Digest # refers to the Digest module defined at the top level
    end
    end

    Jesus.
     
    Jesús Gabriel y Galán, Nov 7, 2010
    #4
    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. Sander Odekerken

    Meaning of output value?

    Sander Odekerken, May 18, 2004, in forum: VHDL
    Replies:
    2
    Views:
    2,558
    John_H
    May 18, 2004
  2. Parthav
    Replies:
    4
    Views:
    2,040
    Mike Treseler
    Jan 13, 2006
  3. Frank

    Meaning of <%#

    Frank, Dec 30, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    593
  4. .NET Follower

    Meaning Of Timeout in FormsAuthentication???

    .NET Follower, Feb 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    .NET Follower
    Feb 6, 2004
  5. Replies:
    4
    Views:
    817
Loading...

Share This Page