Yard doc和`define_method`
有没有办法在YardDoc中注释使用define_method
的方法 ?
我试过这个:
%w(one two three).each do |type| # The #{type} way # @return [String] the #{type} way define_method("#{type}_way") do ... end end
但是,不幸的是,没有工作。
如果将方法创建移动到类方法中,则可以使用宏:
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
) – 双向