Nic*_*las 6 ruby code-documentation yard
我想使用 YARD 更好地记录此 na\xc3\xafve 记忆方法的返回类型:
\n# Ensures that given block is only executed exactly once and on subsequent\n# calls returns result from first execution. Useful for memoizing methods.\n#\n# @param key [Symbol]\n# Name or unique identifier of the method that is being memoized\n# @yield\n# @return [Object] Whatever the block returns\ndef memoize(key, &_block)\n return @memos[key] if @memos.key?(key)\n\n @memos[key] = yield\nend\nRun Code Online (Sandbox Code Playgroud)\n注意:@memos此类的#initialize方法上正在初始化一个空哈希。
现在,很高兴表达该方法始终返回给定块返回的任何内容,但我不确定如何最好地做到这一点。我想过使用@yieldreturn,但随后需要像泛型这样的东西来表达类似的东西:
# @yieldreturn [<T>]\n# @return [<T>] Whatever the block returns\nRun Code Online (Sandbox Code Playgroud)\n但我相信那不是有效的庭院。
\n有什么方法可以表达返回类型和提供的块的这种联系吗?任何建议表示赞赏:)
\n| 归档时间: |
|
| 查看次数: |
638 次 |
| 最近记录: |