Document block taking no parameters
Asked Answered
H

1

6

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 :)

Herrmann answered 22/4, 2013 at 9:28 Comment(1)
Thanks to @sawa for the edit, but the question is primarily about the YARD documentation, not the block-usage pattern.Herrmann
H
3

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
Herrmann answered 22/4, 2013 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.