The ::
is the scope resolution operator. What it does is determines what scope a module can be found under. For example:
module Music
module Record
# perhaps a copy of Abbey Road by The Beatles?
end
module EightTrack
# like Gloria Gaynor, they will survive!
end
end
module Record
# for adding an item to the database
end
To access Music::Record
from outside of Music
you would use Music::Record
.
To reference Music::Record
from Music::EightTrack
you could simply use Record
because it's defined in the same scope (that of Music
).
However, to access the Record
module responsible for interfacing with your database from Music::EightTrack
you can't just use Record
because Ruby thinks you want Music::Record
. That's when you would use the scope resolution operator as a prefix, specifying the global/main scope: ::Record
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…