Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在类层次结构中强制执行单例?我没有这方面的用例,我只是好奇它是否可能?
在某种意义上的层次结构,从这个类继承的所有类也将是单例。
没有。你可以帮助他们成为单例,但你不能强制他们的构造函数的访问控制,所以不可能强迫他们成为单例。
我正在尝试将给定字段与模型Header中的其他字段进行比较。Alarm正如您在代码中看到的,我通过 3 个不同的步骤过滤警报。前 2 个工作完美。但是,最后一个不起作用。它说:
Header
Alarm
undefined method `wh