在 Ruby 超类中放置实用方法的位置
我正在编写一个 Ruby 对象,它将用作从它继承的任意类的超类。该类有几个定义良好的方法,以及许多小的实用方法,可以从主要方法中分解出一些工作。我希望这些方法对于子类是不可见的,并且不会引起命名冲突。对于这种情况,最佳做法是什么?
编辑:“不可见”是指不会意外出现命名冲突或调用。我意识到总会有一些偷偷摸摸的方法来接近班级成员。
I'm writing a Ruby object that will be used as the superclass of arbitrary classes that inherit from it. The class has a couple well-defined methods, along with many small utility methods, to factor out some work from the main methods. I want those methods to be invisible from subclasses, with no chance of causing naming conflicts. What is the best practice for this situation?
Edit: By "invisible", I mean that there won't accidentally be naming conflicts or invocations. I realize there will always be sneaky ways to get at class members.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将它们设为私有并命名为
def __some_utility_method
然而,在 Ruby 中,没有什么是真正“不可见的”
Make them private and name them
def __some_utility_method
However, in Ruby nothing is really ever "invisible"