Double colon in class definition?

R

Robert La Ferla

What does the double colon mean in a class definition. e.g.
ActiveRecord::Base ? I couldn't locate it in the docs. I suspect
it's akin to a category or a namespace. The only documentation on
double-colon that I have found indicates that "::" is used to make
class methods easier to read since "." will also call a class method.
 
Y

yermej

What does the double colon mean in a class definition. e.g.
ActiveRecord::Base ? I couldn't locate it in the docs. I suspect
it's akin to a category or a namespace. The only documentation on
double-colon that I have found indicates that "::" is used to make
class methods easier to read since "." will also call a class method.

In this case, it indicates that Base is a class within the
ActiveRecord module. More generally, it's used to reference a constant
(modules & classes are constants) within a module (similar to a
namespace) or a class. As in:

irb> Object::Fixnum.class
=> Class
irb> Object::RUBY_VERSION.class
=> String
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top