如何记录 Rails 模型内部的隐式方法?
我在 Rails 项目上使用 YARD ,想知道如何在 Rails 模型上记录继承/运行时方法?例如,记录 User
模型上 first_name
属性的存在。
I'm using YARD on my Rails project and was wondering how I would go about documenting inherited/runtime methods on a Rails model? For instance documenting the existence of a first_name
attribute on a User
model.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能那样做,恕我直言。
问题在于这些方法并不真正“存在”;它们是在运行时第一次调用时通过
method_missing
挂钩“动态创建”的。其他文档生成系统有方法声明“隐式”方法。例如,NaturalDocs 有一个 函数关键字,允许您创建仅存在于评论中的函数。我对YARD不太熟悉,但似乎没有类似的功能。
祝你好运!
You can't do that, IMHO.
The trouble is that those methods don't really "exist"; They are "created on the fly" via
method_missing
hooks, the first time they are invoked, on runtime.Other documentation generation systems have ways to declare "implicit" methods. For example NaturalDocs has a function keyword that allows you to create functions that only exist on the comments. I'm not familiar enough with YARD, but it seems it doesn't have a similar functionality.
Good luck!