JoJ*_*JoS 7 ruby documentation yard
有没有办法评论define_method在YardDoc中定义的方法?
我试过这个:
%w(one two three).each do |type|
# The #{type} way
# @return [String] the #{type} way
define_method("#{type}_way") do ... end
end
Run Code Online (Sandbox Code Playgroud)
但是,不幸的是,没有工作.
如果将方法创建移动到类方法中,则可以使用宏:
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
Run Code Online (Sandbox Code Playgroud)
YARD输出:
Run Code Online (Sandbox Code Playgroud)- (String) one_way单向的
返回:
(
String) - 单向
Run Code Online (Sandbox Code Playgroud)- (String) three_way三种方式
返回:
(
String) - 三种方式
Run Code Online (Sandbox Code Playgroud)- (String) two_way这两种方式
返回:
(
String) - 双向
| 归档时间: |
|
| 查看次数: |
640 次 |
| 最近记录: |