5

I have an object with a method returning a lambda:

class Book
  def mark_page(marker_color)
    lambda do |page|
      page.mark(marker_color)
    end
  end
end

And I want to document this Book#mark_page method using yardoc syntax. However, I cannot find anything about lambdas in this documentation.

Intuitively, I'd go for something like:

# @return [Proc(Page)]

Since yardoc.org/types is parsing it as:

a Proc containing (a Page)

PS: not so sure about the documentation tag. Feel free to remove it if not appropriate...

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
  • `# @return [Proc]` See https://rubydoc.info/gems/yard/file/docs/Tags.md#return. Note that you're returning a `Proc` object, so the P needs to be uppercase, not lowercase. Not sure what you think `{Page}` means in this context, but it doesn't belong. – anothermh Jan 23 '20 at 01:33
  • 1
    @anothermh — the `{Page}` is the whole point of my question. I want to tell that I am returning a `Proc` which takes a `Page` as argument. Quite similar to JSDoc when you return a function and explicit it's arguments. From your given link, I end up thinking `Proc(Page)` is the closest solution (https://yardoc.org/types). But I'm not sure it is semantically correct. – Ulysse BN Jan 23 '20 at 09:11
  • That's not something you would comment with yardoc in `@return`. `@return` is to say "here is the class of the object or the classes within a collection of objects that are returned by this method." Your guess at using `Proc(Page)` is wrong and misunderstands the docs you link to. Of course, there's no reason you _can't_ do all this; they're just comments, after all. But don't expect anyone else to understand what you're doing if you contravene the docs. – anothermh Jan 23 '20 at 18:26
  • @anothermh hence my question for a clearer way of doing so... – Ulysse BN Jan 23 '20 at 18:28

0 Answers0