What does ::
mean in Ruby? E.g. Foo::Bar
.
3 Answers
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 areceiver::Thing
method call is actually an attempt to access a constant calledThing
in the receiver unless the method invocation has a parameter list between parentheses.

- 95,083
- 20
- 220
- 214

- 811,555
- 193
- 1,581
- 1,452
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.

- 11,165
- 9
- 62
- 113
-
What's fancy about it? It's the normal way to do this. – Chuck Feb 16 '10 at 22:47
-
@Chuck that's true. I'm speaking from my VB/C# prospective. – Achilles Feb 17 '10 at 03:22
It accesses constants in a given class or module. E.g. ActiveRecord::Base
is the constant Base
defined in the module ActiveRecord
.

- 363,768
- 54
- 674
- 675