简体   繁体   中英

Explicitly inherit from a class in the base module

I have a class that inherits from class User.

eg

class MyClass < User

end

In my code base I have a class user

class User

end

However I also have a plugin that provides a User class in a module TheirModule::User. This is a plugin that my application is tied to and I cannot remove it at the moment, however that is what I would prefer to do.

From the console I can access MyClass and the inheritance is correctly determined. However when running the application there seems to be some confusion which User class I intend to inherit from and therefore the inheritance fails.

Is there a way to explicitly inherit from my User class and prevent confusion with the TheirModule::User

If you want MyClass to inherit from User class, you can put the User class inside a module, for example MyModule.

class MyClass < MyModule::User
end
class MyUser < User
end

class MyClass < MyUser
end

This way MyClass will inherit from both your own MyUser class and from TheirModule::User.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM