文档块不带参数

时间:2013-04-22 09:28:53

标签: ruby block yard

我正在写我用YARD记录的第一颗宝石。我让我的一个类有一个构造函数,它需要一个不带参数的块 1

YARD提供@yield [params] description标记来根据方法传递给它的参数来描述块参数,但如果params列表为空,则它不能正确格式化。我该如何记录没有参数的块?

1 :从技术上讲,我甚至都不是yield。我的代码看起来像这样:

def initialize(&block)
  define_singleton_method(:create, block)
  create
  class << self; undef_method :create; end
end

...因此该块包含要在新创建的对象的上下文中运行的代码。如果由于某种原因这是一个可怕的想法,我也很高兴知道这一点:)

1 个答案:

答案 0 :(得分:1)

我在YARD的github页面上找到了old issue;看起来应该省略参数块:

# @yield Description of the block here
def initialize(&block)
  define_singleton_method(:create, block)
  create
  class << self; undef_method :create; end
end
相关问题