RubyMine - 自动检测.each,.map和其他迭代器类型

jtm*_*mon 9 ruby ruby-on-rails rubymine

在RubyMine中我可以写

# @param [Array<MyClass>] things
def foo(things)
end
Run Code Online (Sandbox Code Playgroud)

和RubyMine将自动完成MyClass方法things.first.*.但是,当我循环遍历每个时,例如:

# @param [Array<MyClass>] things
def foo(things)
    things.each { |t| t.* }
end
Run Code Online (Sandbox Code Playgroud)

RubyMine失去了它的类型推断.我知道我可以添加注释来指定块参数类型,但循环遍历某种类型的对象应该只生成该类型的参数.

有什么办法,我可以写的RubyMine自定义规则,这样.each,.map和其他迭代器被认为具有可变的呼吁的类型?

BVB*_*BVB 1

根据我的研究,您似乎可以像这样注释:

# @param [Array<MyClass>] things
def foo(things)
  things.each {
    # @type [MyClass] t 
    |t|
    t.*
  }
end
Run Code Online (Sandbox Code Playgroud)

资料来源:https ://youtrack.jetbrains.com/issue/RUBY-9142#comment=27-787975