"class Admin::UsersController < ApplicationController". What does the double colon do here?

I saw this on a Gem implementation and don’t understand why it needed “::UsersController” at all.

My understanding that it is trying to find the relative path of UsersController, but why is it necessary to be there?

This is one of the ways to provide namespacing in Ruby and avoid same-name conflicts (e.g. with user code or other gems).

class Admin::UsersController …

end

is equivalent to

module Admin

class UsersController …

end

end

Hi,

class Admin::UsersController ... end

is equivalent to

module Admin class UsersController ... end end

Only partly right. There is a slight difference.

As long as the module (or namespace) alread exists you are right. But if you didn't encounter a „module Admin“ statement before the „class Admin::UsersController“ will fail with an „NameError: uninitialized constant Admin“. So

module Admin   class UsersController   end end

will always create the module if it doesn't exist, yet while

class Admin::UsersController end

will not do this and error out.

Best regards,

- -- Christian Kruse http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services