tags:

views:

131

answers:

4

What does :: mean in Ruby? I see it used when calling a lot of gems.

Example:

ActiveRecord::Base.establish_connection(......

+1  A: 

It accesses constants in a given class or module. E.g. ActiveRecord::Base is the constant Base defined in the module ActiveRecord.

sepp2k
+6  A: 

It's called a scope resolution operator. Basically a fancy way of referencing a class within a namespace. ActiveRecord is the namespace and Base is the class.

Achilles
What's fancy about it? It's the normal way to do this.
Chuck
@Chuck that's true. I'm speaking from my VB/C# prospective.
Achilles
+6  A: 

According to ruby-doc.org:

When a receiver is explicitly specified in a method invocation, it may be separated from the method name using either a period “.” or two colons “::”. The only difference between these two forms occurs if the method name starts with an uppercase letter. In this case, Ruby will assume that a receiver::Thing method call is actually an attempt to access a constant called Thing in the receiver unless the method invocation has a parameter list between parentheses.

Mark Byers
A: 

In the case you've shown, it is used to reference the module Base which is nested in module ActiveRecord. In effect, this defines a namespace hierarchy. See here for more details.

Matt Davis