命名空间和混入
我正在尝试清理我们的命名空间。基本上我们的设置有点像
class myClass
include myModule1
include myModule2
@important_var #critical instance variable
基本上@important_var是一个telnet处理程序,几乎所有方法都需要访问它。这与现在的设置方式配合得很好。不幸的是 myModule1 & myModule2 变得越来越大。所以我一直遇到方法的命名空间冲突。
我喜欢使用模块包装器访问方法,例如:
myClass_instance.myModule1.a_method
但我不知道如何做到这一点或其他一些更清晰的名称间距想法?
I'm trying to clean up our namespaces. Basically our setup is somewhat like
class myClass
include myModule1
include myModule2
@important_var #critical instance variable
Basically @important_var is a telnet handler that almost all methods need to get at. This works fine with the way it is setup right now. Unfortunately myModule1 & myModule2 are getting huge. So I keep running into namespace collisions for the methods.
I'd love to access methods with a module wrapper eg:
myClass_instance.myModule1.a_method
But I can't figure out how to do this or some other cleaner name spacing idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于为模块内的方法构建命名约定的想法,我准备了一个自动化版本:
myinclude
包含模块并检查每个方法是否以定义的前缀开头。如果没有定义该方法(通过alias
)。此外,您还可以获得一个名为类似前缀的方法。此方法将调用转发给原始模块方法。请参阅代码末尾的示例。Based on the idea to build a naming convention for the methods inside the modules I prepared a automated version:
myinclude
includes the module and checks, if each method begins with a defined prefix. If not the method is defined (viaalias
). In addition you get a method called like the prefix. This method forwards the call to the original module-method. See example in the code end.