使用YARD进行Ruby文档的内部注释?

Dav*_*man 6 ruby rdoc yard

我正在将从RDoc维护的rubygem切换到YARD文档.但是,代码中有一些关键注释只需要保留在代码中,不应该出现在文档中.例如:

##
# SomeClass documentation here.
#--
# CRITICAL comment that should be in the code but not in the documentation,
#          and must be at this particular spot in the code.
#++
# more documentation that follows the critical comment block, but this part 
# should be in the generated documentation
class SomeClass
    ...
end
Run Code Online (Sandbox Code Playgroud)

RDoc尊重#--#++门,但YARD没有.什么(如果存在)是在YARD标记中做类似事情的语法?

Ale*_*xis 5

好吧,以最简单、快速和肮脏的形式,解决方案很简单 - 只需使用任何自定义(码未知)标签名称即可。例如:

##
# SomeClass documentation here.
#
# @internal_note CRITICAL
#   comment that should be in the code but not in the documentation,
#   and must be at this particular spot in the code.
#
# more documentation that follows the critical comment block, but this part 
# should be in the generated documentation
Run Code Online (Sandbox Code Playgroud)

这里唯一的问题是yard会警告您每次出现@internal_note:

[warn]: Unknown tag @internal_note in file ... near line xxx
[warn]: Unknown tag @internal_note in file ... near line yyy
...
Run Code Online (Sandbox Code Playgroud)

我真的认为应该有官方的方法来抑制不需要的警告,但不幸的是我找不到它。不过,您可以尝试以下方法之一:

  1. yardoc -q# 问题:也会抑制有用的信息
  2. 您可以创建yardinit.rb包含以下内容的文件:

    YARD::Tags::Library.define_tag('INTERNAL NOTE', :internal_note)
    
    Run Code Online (Sandbox Code Playgroud)

    然后生成文档

    yardoc -e './yardinit.rb'
    
    Run Code Online (Sandbox Code Playgroud)
  3. 有一个yard插件可以抑制所有未知标签警告https://github.com/rubyworks/yard-shutup

    它看起来不太活跃,也gem install yard-shutup不起作用,但你可以手动安装并尝试一下