Early Access Program Features

What’s Mining: Inline Method Refactoring

Hello guys,

RubyMine team recently was on New Year and Christmas holidays, less than a week has passed since our days off ended, however today we want to show you the new cool feature coming in 4.0 – inline method refactoring.

We are pretty sure most of you are already familiar with extract method refactoring and many of you use it on daily basis. Inline method refactoring is the inverse one for extract method. Let me show you several examples on how it works.

Operations Priority Control

Let’s go to the code fragment:

Place caret on the sum(1) call and invoke Inline method action.

If method has only one usage the second option is not available. So we choose to remove the method and inline the invocation. And in result we get:

Here you can see that RubyMine was smart enough to inline argument default value and simplify the method body by removing unnecessary return statement. (By the way you do know that RubyMine has “Remove unnecessary return statements” intention action, right?)

Local Variables Control

RubyMine analyzes the way locals are used inside a method body you are about to inline and inlines them if it is possible to simplify the result. Let’s take a look:



Here you can see that method parameter 'a' was successfully inlined, and parameter 'b' was renamed to 'b1' to avoid conflicts.

Execution Flow Control

RubyMine guarantees that your program semantics won’t be changed after refactoring.

Accessibility Control

It is guaranteed that all the methods, constants, etc. used in method body are accessible on the call site.



You can see that the 'CCC' constant was changed to a qualified call of 'AAA::CCC'.

Of course there are much more supported cases, and we hope you’ll spend some time exploring and enjoying them. We hope inline method refactoring will become your everyday tool you can rely on.

Stay tuned for more exciting news coming soon!

Develop with pleasure!
-JetBrains RubyMine Team

image description