Tag: 代码注释

在Ruby中以编程方式访问属性/方法注释

有没有办法以编程方式访问方法注释? 或属性评论? 我想用它作为文档中方法的描述,我不希望它是静态的或用rdoc或等效的方法生成。 以下是Ruby类的示例: Class MyClass ## # This method tries over and over until it is tired def go_go_go(thing_to_try, tries = 10) # :args: thing_to_try puts thing_to_try go_go_go thing_to_try, tries – 1 end end 基本上,我希望能够做到以下几点: get_comment MyClass.gogogo # => This method tries over and over until it is tired