English 中文(简体)
我可以向RubyMine告知或提示一个本地或实例变量的类型吗?
原标题:Can I tell or hint to RubyMine what type a local or instance variable is?

我试图利用RubyMine的快速博士和代码完成。

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

...这些评论对参数、 返回类型甚至打印收藏效果很好。 但我找不到类似标签, 比如本地变量或本地变量, 并且非常肯定Ruby(我有没有提到我是新来的吗? )

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

最佳回答

这似乎是“强势”即将到来的

“本地变量可以是附加说明的,无论有无变量名称:”

# @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

"多任务也得到支持:"

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

"但是在多任务的情况下,没有 var name 的表格是行不通的(这是可以论证的,但我倾向于说,它可能导致一些错误)

块参数也可以附加说明:”

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

“要注意的是,类型说明应放在行或 { 和区块参数列表之后, 以帮助避免可能的模糊性。 对于一行来说, 它看起来很麻烦, 但我不确定它们会有很多附加说明。 总之, 任何建议都是非常受欢迎的。 ”

问题回答

它不是100%地回答这个特定的问题, 而是可以指向其他有用的把戏。

在测试中,我这样做是为了欺骗RubyMine(5. 0.2)。

user = users(:normal) || User.new

由于有固定装置, 我确定用户( : 第一) 会返回对象, 并且因为使用。 NEW - IDE 认为应该是用户实例 。

似乎没有。我建议,在问题追踪器中查找现有的功能请求,并加上让大家听到你的声音。

http://youtrack.jetbrains.com/issu/RUBY-9142" rel=“no follow'>http://youtrack.jetbrains.com/issu/RUBY-9142

<强 > 更新

这一特性现在与RubyMine 7.0(Tsubaki) EAP(138.1968)和更高(但请注意,Rubymine 7.0目前在EAP(即贝塔)中,这总有可能不会让它进入最后的解剖。 )





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签