You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby Yard如何标注多类型参数?(对应TypeScript联合类型)

SketchUp Ruby代码中YARD多类型参数的标注方式

你习惯用TypeScript,现在迁移SketchUp旧Ruby代码库写文档,想把这段TypeScript的参数类型标注转换成Ruby的YARD格式:

function get_definition(instance: ComponentInstance | Group | Image)

你尝试的写法里用了TypeScript的|分隔类型,这不符合YARD的语法规范。正确的YARD多类型参数标注应该用逗号分隔类型,写法如下:

# @param [ComponentInstance, Group, Image] instance
def self.get_definition(instance)
  # 方法实现
end

补充小提示:如果这些类型是SketchUp API自带的类,直接写类名即可,YARD会自动识别对应API的关联关系。

内容的提问来源于stack exchange,提问作者Nanachi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 00:54:33