9

In RubyMine I can write

# @param [Array<MyClass>] things
def foo(things)
end

and RubyMine will autocomplete MyClass methods for things.first.*. However, when I loop through each, like:

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

RubyMine loses its type inference. I know I can add comments to specify block parameter types, but looping through an object of some type should only yield parameters of that type anyway.

Is there any way I can write a custom rule for RubyMine so that .each, .map, and other iterators are presumed to have the type of the variable its called upon?

jtmarmon
  • 5,727
  • 7
  • 28
  • 45
  • Contact support i 've meet them personaly they are REALY quick to respond . – plombix Sep 07 '16 at 13:11
  • this might be useful.! [http://stackoverflow.com/questions/24318226/how-to-disable-rubymine-code-completion-after-comment-line-ending-in-period](http://stackoverflow.com/questions/24318226/how-to-disable-rubymine-code-completion-after-comment-line-ending-in-period) – srihari sairam Ventrapragada Sep 10 '16 at 08:22
  • there's now an issue on jetbrains for this https://youtrack.jetbrains.com/issue/RUBY-18531 – jtmarmon Nov 27 '16 at 21:20

1 Answers1

1

From my research, it looks like you may be able to annotate like so:

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

Source: https://youtrack.jetbrains.com/issue/RUBY-9142#comment=27-787975

BVB
  • 5,380
  • 8
  • 41
  • 62
  • yeah you can explicitly annotate block params, but the point of my question was that I don't want to have to do that for every enumeration. it should be implicit – jtmarmon Sep 07 '16 at 06:27