干院参数 [英] DRYing yard parameters

查看:152
本文介绍了干院参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了我假设的是一个相当基本的代码宏使用,我有一个哈希结构与多个功能之间共享的多个选项。我希望使用宏只是为了阻止我不得不在这个地方复制这个结构,但似乎并不像这样工作。



我期望工作的是:

 #@macro [ new] my_hash 
#@param $ 1 [Hash,Array< Hash>]输入my_hash
#@option $ 1 [String]:A的值
#@option $ 1 [String] b的值B.
#@option $ 1 [String]:c C的值

##
#my_func的东西
#@macro my_hash h1
def my_func h1
end

##
#other_func做东西
#@macro my_hash h2
def other_func h2,a,b
end

,并正确记录h1和h2。我想我已经弄清楚,至少$ 1不起作用,而是从功能本身,但我可以调用这两个参数h1和代替$ 1与h1在宏,我仍然没有得到我想要的。



http://rubydoc.info/docs/yard/file/docs/Tags.md#macro 将表明我可以做到这一点(注意我用@!宏和一些没有但似乎没有工作)。



我不知道很多关于院子,但这只是不工作?有什么类似的东西可以做到以达到我的成果吗?有没有一个调试功能,可以解释这一点,在院子里的服务器控制台上没有出现错误?



谢谢

解决方案

这可以与yardoc 0.9.8(可能是任何版本)一起使用:

 #@ !宏my_hash 
#@param $ 1 [Hash,Array< Hash>]输入my_hash
#@option $ 1 [String]:A的值
#@option $ 1 [String] b的价值B.
#@option $ 1 [String]:c C.的价值

##
#my_func的东西
#@macro my_hash
def my_func h1
end

##
#other_func确定东西
#@macro my_hash
def other_func h2,a,b
结束

注意丢失的感叹号!当用 @macro 调用宏时。这是正确的码语法


I've got what i assumed was a fairly basic yard macro usage where i have a Hash structure with a number of options that is shared between multiple functions. I was hoping to use a macro simply to prevent me having to replicate this structure all over the place but it doesn't seem to work like that.

What i expected to work was:

# @macro [new] my_hash
#   @param  $1 [Hash,Array<Hash>] Inputted my_hash
#   @option $1 [String] :a Value for A.
#   @option $1 [String] :b Value for B.
#   @option $1 [String] :c Value for C.

##
# my_func does stuff
# @macro my_hash h1
def my_func h1
end

## 
# other_func does stuff
# @macro my_hash h2
def other_func h2, a, b
end

and have h1 and h2 documented correctly. I think i've figured out that at least the $1 doesn't work like that instead takes from the function itself but i can call the both parameters h1 and replace $1 with h1 in the macro and i still don't get what i want.

The "Defining simple macros" example at http://rubydoc.info/docs/yard/file/docs/Tags.md#macro would indicate that i can do this (note that i find examples with @!macro and some without but neither seem to work).

I don't know a lot about yard but does this just not work? Is there something similar that i can do to achieve my result? is there a debugging function that would explain this as no errors come up in the yard server console?

Thanks

解决方案

This works with yardoc 0.9.8 (probably any version):

# @!macro my_hash
#   @param  $1 [Hash,Array<Hash>] Inputted my_hash
#   @option $1 [String] :a Value for A.
#   @option $1 [String] :b Value for B.
#   @option $1 [String] :c Value for C.

##
# my_func does stuff
# @macro my_hash
def my_func h1
end

##
# other_func does stuff
# @macro my_hash
def other_func h2, a, b
end

Note the missing exclamation mark ! when calling the macro with @macro. This is the correct yardoc syntax.

这篇关于干院参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆