我可以告诉或提示 RubyMine 本地变量或实例变量是什么类型吗? [英] Can I tell or hint to RubyMine what type a local or instance variable is?

查看:59
本文介绍了我可以告诉或提示 RubyMine 本地变量或实例变量是什么类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试利用 RubyMine 快速文档和代码完成功能.我很高兴地发现它整合了 YARD 风格的评论:

# @param [数字] 宽度# @param [Array] 值# @return [小工具]def foo(宽度,值)

...这些注释对于参数、返回类型,甚至类型集合都非常有用.但是我找不到任何类似的标签,例如实例或局部变量,而且我很确定 Ruby 中没有可用的类型转换(我有没有提到我是新手?)

有没有办法让 RubyMine 了解本地和/或实例变量的类型?

解决方案

看来这是即将推出,基于最近发布到 Matt Connolly 引用的问题跟踪器的评论:http://youtrack.jetbrains.com/issue/RUBY-9142#comment=27-787975

"局部变量可以使用或不使用变量名进行注释:"

# @type [字符串]my_var = magic_method# @type my_var [字符串]my_var = magic_method# @type [String] my_varmy_var = magic_method# @type [String] my_var 并且允许一些文档my_var = magic_method

还支持多任务:"

# @type my_var [String] 第一部分# @type other_var [Range] 第二部分my_var, other_var = magic_method

但是在多重赋值的情况下,没有 var name 的表单将不起作用(这是有争议的,但我倾向于它可能会导致一些错误)

也可以注释块参数:"

method_with_block 做# @type [字符串] param1# @type [范围] param2|参数 1, 参数 2 |# 一些代码...结尾

"需要注意的是,类型注释要放在 do 或 { 之后和块参数列表之前,以帮助避免可能的歧义.在单行的情况下,它看起来很麻烦,但我不确定它们是进行大量注释.无论如何,非常欢迎任何建议."

I'm trying to leverage the RubyMine quick-docs and code completion. I was pleased to discover how well it integrated the YARD-style comments:

# @param [Numeric] width
# @param [Array<String>] values
# @return [Widget]      
def foo(width, values)

... these comments work great for parameters, return-types, even typed collections. But I can't find any similar tags for instance or local variables, and am pretty sure there's no type casting available in Ruby (Did I mention I'm new to this?)

Is there any way to clue RubyMine in to the types of local and/or instance variables?

解决方案

It appears this is forthcoming, based on a recent comment posted to the issue tracker referenced by Matt Connolly: http://youtrack.jetbrains.com/issue/RUBY-9142#comment=27-787975

"local variables can be annotated with or without variable name:"

# @type [String]
my_var = magic_method

# @type my_var [String]
my_var = magic_method

# @type [String] my_var
my_var = magic_method

# @type [String] my_var And some documentation is allowed
my_var = magic_method

"Also multi-assignments are supported:"

# @type my_var [String] The first part
# @type other_var [Range] The second part
my_var, other_var = magic_method

"But in the case of a multi-assignment the form without var name would not work (this is arguable, but I incline to that it may lead to some errors)

Also block parameters can be annotated:"

method_with_block do
  # @type [String] param1
  # @type [Range] param2
  | param1, param2 |
  # some code...
end

"The thing to note is that type annotations are to be placed after do or { and before block parameters list, to help avoiding probable ambiguity. In the case of one-liners it looks cumbersome, but I am not sure they are to be heavily annotated. Anyway, any suggestions are very welcome."

这篇关于我可以告诉或提示 RubyMine 本地变量或实例变量是什么类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆