More Types Intelligence in RubyMine

In the previous article covering type inference we’ve reviewed the following cases:

  • Type Inference for local variables
  • Detecting for index variable type
  • Understanding true, false and nil

But there’s more, much more…
Let’s see more intelligence RubyMine shows when editing Ruby code.

Unknown Method Calls

If in your code you make a method call or reference an attribute that RubyMine for some reason cannot resolve, you will be notified about it by the appropriate inspection but only once for this particular method and current variable. And your code will not look all red.

If you press Ctrl+B/⌘ B on such method call it will resolve to the first occurrence where inspection error is shown.

Custom Error Types

RubyMine correctly resolves your custom exceptions and their methods when you want to handle errors in your code.

class MyError err

Code completion shows the methods and attributes of custom error class MyError.

Block Variables Type

Using yield and blocks is one of the many things that make the Ruby language interesting. RubyMine understands that and can see the type of block variables used within block calls.
def my_iterate(count)
i = 0
while i <= count do
yield i

my_iterate(5) do |i|
puts(“Current: ” + i.to_s)

So code completion only shows the relevant items.

Guessing Return Type from Method Comment

For RubyMine even the comments you write in your code are important and it uses them to help you in your work. RubyMine can get the type of method return value from method comment and then use it for more precise code completion.

These are some of the basic code editing and code completion features that help being more productive.

Stay tuned for lots more like this. We’ll cover Ruby on Rails related features next time.

image description

Discover more