庭院doc和`define_method` [英] Yard doc and `define_method`
本文介绍了庭院doc和`define_method`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 YardDoc >中定义 define_method
a>?
Is there a way to comment methods defined with define_method
in YardDoc?
我尝试过:
%w(one two three).each do |type|
# The #{type} way
# @return [String] the #{type} way
define_method("#{type}_way") do ... end
end
但不幸的是,不工作。
推荐答案
如果将方法创建移动到类方法中,可以使用宏:
If you move the method creation into a class method, you could use a macro:
class Foo
# @!macro [attach] generate
# @method $1_way
# The $1 way
# @return [String] the $1 way
def self.generate(type)
define_method("#{type}_way") do
end
end
generate :one
generate :two
generate :three
end
YARD输出:
- (String) one_way
单向
返回:
( String
) - 单向
- (String) three_way
三种方式
返回:
( String
) - 三种方式
- (String) two_way
双向
返回:
( String
) - 双向
这篇关于庭院doc和`define_method`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文