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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With