Double colons before class names in Ruby?

It means that you’re referring to the constant File from the toplevel namespace. This makes sense in situations like this:

class MyClass #1
end

module MyNameSpace
  class MyClass #2
  end

  def foo # Creates an instance of MyClass #1
    ::MyClass.new # If I left out the ::, it would refer to
                  # MyNameSpace::MyClass instead.
  end
end

Leave a Comment