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
[/code]
I know that it represents a constant but how I should interpret that.
···
--
Posted via http://www.ruby-forum.com/.
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
[/code]
I know that it represents a constant but how I should interpret that.
--
Posted via http://www.ruby-forum.com/.
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.
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
[/code]
I know that it represents a constant but how I should interpret that.
--
Posted via http://www.ruby-forum.com/.
Best regards,
Zhi-Qiang Lei
zhiqiang.lei@gmail.com
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.
···
On Sun, Nov 7, 2010 at 9:37 AM, Zhi-Qiang Lei <zhiqiang.lei@gmail.com> wrote:
What about code like:
::Digest::MD5.hexdigest "xxx"
Why is the :: before Digest module nothing?