Ruby 问大佬一个 Ruby 问题,关于方法类型

lengain · March 01, 2023 · Last by Abson replied at March 07, 2023 · 481 hits

ruby 方法的形参和返回值都不需要声明,但是我用 rubyMine 编辑器的时候,看到to_s等系统方法后面都跟着→String的声明, 点击→String 跳转到def to_s: () -> String的一个声明

但是我自己写的方法没办法添加类似→String的这种声明,有没有大神知道怎么添加这样的方法声明,不吝赐教一下

https://github.com/ruby/rbs

这个是 rbs, ruby 的类型标注

Reply to liuminhan

了解了。谢谢。

Reply to liuminhan

感觉和 YARD 差不多,但是 YARD 在注释里不影响代码

使用 YARD,# @return [String]

You need to Sign in before reply, if you don't have an account, please Sign up first.