[英]Explicitly inherit from a class in the base module
I have a class that inherits from class User. 我有一个从User类继承的类。
eg 例如
class MyClass < User
class MyClass <用户
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. 从控制台,我可以访问MyClass,并且继承已正确确定。 However when running the application there seems to be some confusion which User class I intend to inherit from and therefore the inheritance fails.
但是,在运行该应用程序时,似乎有些混乱,我打算从哪个User类继承,因此继承失败。
Is there a way to explicitly inherit from my User class and prevent confusion with the TheirModule::User 有没有一种方法可以显式地从我的User类继承,并防止与他们的模块::用户混淆
If you want MyClass to inherit from User class, you can put the User class inside a module, for example MyModule. 如果希望MyClass继承自User类,则可以将User类放在模块中,例如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. 这样,MyClass将从您自己的MyUser类和从他们的Module :: User继承。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.