Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document block taking no parameters

Tags:

ruby

block

yard

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

like image 313
Chowlett Avatar asked Nov 02 '22 23:11

Chowlett


1 Answers

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
like image 171
Chowlett Avatar answered Nov 13 '22 17:11

Chowlett