Вопрос

I'm writing my first gem which I'm documenting with YARD. I've made one of my classes have a constructor which expects a block which takes no arguments1.

YARD provides the @yield [params] description tag to describe a block argument in terms of the parameters a method will pass to it, but it doesn't format properly if the params list is empty. How should I document a block with no parameters?

1: Technically, I'm not even yielding to the block; I have code that looks like this:

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

...so the block contains code to be run in the context of the newly-created object. If this is a terrible idea for some reason, I'd be glad to know that, too :)

Это было полезно?

Решение

I found an old issue on YARD's github page; it looks like the parameters block should just be omitted:

# @yield Description of the block here
def initialize(&block)
  define_singleton_method(:create, block)
  create
  class << self; undef_method :create; end
end
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top