amingilani amingilani - 4 months ago 9
Ruby Question

Can a ruby class method inherit from another class?

I read here that a ruby class can only inherit from one class, and can

include
modules.

However, the devise module defines controllers like this:

class Users::PasswordsController < Devise::PasswordsController
...
end


Now, given that
Users
is probably a class, with
PasswordsController
being a method:

>> Devise::PasswordsController.class
=> Class


How is it that a method in a class inherits from another class?

Answer
class Users::PasswordsController < Devise::PasswordsController
...
end

In the above code, Users is the module and PasswordsController is the class inside Users module. Similarly Devise is the module and PasswordsController is the class inside Devise module.

so when you run

Users::PasswordsController.class
#=> Class
Users.class
#=>Module
Comments