Document a method returning a lambda
Asked Answered
D

0

6

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...

Delphiadelphic answered 22/1, 2020 at 10:7 Comment(3)
# @return [Proc] See 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.Gybe
@Gybe — 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 (yardoc.org/types). But I'm not sure it is semantically correct.Delphiadelphic
@Gybe hence my question for a clearer way of doing so...Delphiadelphic

© 2022 - 2024 — McMap. All rights reserved.