[英]Which part of the class name is a module?
In a rails project I have the class: 在Rails项目中,我上了课:
class Police::Office
end
Now I create an Interactor in the same namespace: 现在,我在相同的名称空间中创建一个Interactor:
class Police::Office::ConstructInteractor
end
1. Is this allowed or can it provoke name clashes?
1.这是允许的还是会引起名称冲突?
2. What is
Police::Office::ConstructInteractor
? 2.什么是
Police::Office::ConstructInteractor
?
Is it a class in a module like: 它是模块中的类吗?
module Police::Office
class ConstructInteractor
end
end
Or a class in a class? 还是一堂课?
class Police::Office
class ConstructInteractor
end
end
Thank you
谢谢
1. Is this allowed
1.是否允许
Of course it is allowed. 当然可以。 Classes are allowed to contain constants.
类被允许包含常量。 (BTW: it would have taken you only a couple of seconds to try it out yourself.)
(顺便说一句:您只需花费几秒钟即可自行尝试。)
or can it provoke name clashes?
还是会招致名字冲突?
I have no idea what that means, but again, you can easily test it out yourself by just copy&pasting the code you posted and run it. 我不知道这意味着什么,但是,您只需复制并粘贴您发布的代码并运行它就可以轻松地对其进行测试。
2. What is
Police::Office::ConstructInteractor
?2.什么是
Police::Office::ConstructInteractor
?Is it a class in a module like:
它是模块中的类吗?
module Police::Office class ConstructInteractor end end
Of course not. 当然不是。 You defined
Police::Office
to be a class earlier, so it obviously is a class. 您将
Police::Office
定义为较早的一类,因此显然它是一类。
Or a class in a class?
还是一堂课?
class Police::Office class ConstructInteractor end end
Yes. 是。 But note that this is not a "class in a class".
但是请注意,这不是 “班级中的班级”。 This is a constant in a class.
这是一个类中的常量 。 In Ruby, classes don't nest like they do in Beta, gBeta, Newspeak, or Scala (not even like in Java).
在Ruby中,类不会像在Beta,gBeta,Newspeak或Scala中那样嵌套(甚至在Java中也不一样)。 There is no relationship whatsoever between the class referenced by the constant
Police::Office::ConstructInteractor
and the class referenced by the constant Police::Office
. 有通过不断的引用的类之间没有任何关系,
Police::Office::ConstructInteractor
并通过不断引用的类Police::Office
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.