What's the difference between @tag and @!tag in Yard documentation tool?

最后都变了- 提交于 2019-12-13 02:18:24

问题


While looking at Yard documentation and examples sI found some tags prefixed by an exclamation mark.

I found working examples with and without exclamation marks and I wasn't able to spot the difference, so what changes when @!some-tag is used instead of @some-tag?

For instance this code generate the same documentation for both attr and attr2

class Anything
  # @!attribute [rw] attr
  # @attribute [rw] attr2
end

On the other side, in some examples the importance of exclamation mark is underlined, so it's supposed to do something, but I can't find any documentation on its usage.

@!method Example

Both these comments in a Rails model generate new methods

# @!method with_bang(param)
scope :foo_bar, where(foo: 'bar')
# @method without_bang(param)
scope :foo_baz, where(foo: 'baz')

yard output:


回答1:


The ! modifier in Yard is used when the documented piece of code will generate attributes or methods in its class. For example:

# @!method foo(name, opts = {})
create_a_foo_method

This is telling us that create_a_foo_method will generate a method with the signature def foo(name, ops = {}). You can apply this line of thinking to @!scope, @!visibility, and every other @!tag. As said in Yard documentation, this is useful for documenting DSLs.



来源:https://stackoverflow.com/questions/25039861/whats-the-difference-between-tag-and-tag-in-yard-documentation-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!