Alle venerdì 16 febbraio 2007, firstname.lastname@example.org ha scritto:
On this example, what does “::” mean? If understand correctly it’s
just sort of a naming convention to imply that both the Two and Three
classes belong to the same “group”, as in Net::HTTP and Net::FTP.
So, in essence Two and Three are completely unrelated, and I’d not
even need to have a class named One for it to work, is that right?
If not, please tell me, what exactly is the purpose of “::” on class
:: is the scope operator. It is used to access constants defined in a
module. Since classes are constants, when you write class One::Two,
defining the class Two inside One (where One can be a class or a
you didn’t define One, the code class One::Two will give you a
telling you that the constant One is not initialized:
NameError: uninitialized constant One
Another example of the use of :: is
puts Math::PI, which prints the value of the PI constant
Since PI belongs to the Math module, I couldn’t have written puts PI. In
this raises an exception:
NameError: uninitialized constant PI
I hope this helps.