DelegateClass 和类似方法位于哪个对象/类上?
抱歉标题不好,但我有点迷失了。
我试图找出哪些对象/类的实时方法(例如 DelegateClass)以及这些类型的方法的术语是什么。我正在阅读Ruby 元编程,在书中,这些方法通常被称为模仿方法,但是在互联网上搜索它会给出各种各样的结果,所以我想知道是否有更好的名称他们。
我检查了 DelegateClass 我认为它已添加到对象中,但它不在那里。我可以看到位于同一个 rb 文件中的类 Delegator 和 SimpleDelegator 被添加为常量(尽管我不确定它们是如何添加的)。
Sorry for the poor title, but I'm a bit lost.
I'm trying to figure out on which object/class live methods such as DelegateClass and what is the term for these types of methods. I'm reading Metaprogramming Ruby and, in the book, these methods are generically called Mimic Methods, but searching the internet for this gives all kinds of results, so I'm wondering if there's a better name for them.
I've checked the source code of DelegateClass and I assumed that it was added to Object, but it's not there. I can see the the classes Delegator and SimpleDelegator, which are in the same rb file, are added as constants (although I'm not sure how they are added).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚找到答案。 中的一个私有方法
它是对象edit
,我发现我需要了解的是给定上下文中的当前类是什么?。
Just found the answer. It's a private method in Object
edit
I found out that what I needed to understand is What is the current class? in a given context.
仔细查看文件。
并用于
查找它所在的类。正如评论中提到的,模块上的私有实例方法包含对象上定义的任何内容。
所以不,除了以大写形式调用之外(这使得它看起来像一个常量),
DelegateClass()
无论如何都不是一个特殊的方法。它只是返回一个现场创建的可以继承的匿名类。Look closer at the file.
and use
to find the class where it sits. As mentioned in the comments private instance methods on Module contain anything defined on Object.
So no,
DelegateClass()
is not a special method in any way except for being called in uppercase (which makes it look like a constant). It just returns an anonymous class created on-the-spot that can be inherited from.