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:

Before: 

After: 

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.

Before: 

After: 

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

This entry was posted in Better Code, Feature, WhatsMining and tagged , . Bookmark the permalink.

2 Responses to What’s Mining: Inline Method Refactoring

  1. Refactoring was the reason I picked RubyMine. After reading the book on refactoring Ruby I decided I wanted to use a tool that offer me this refactoring capabilities that I loved in Java. It so happens that I don’t refactor as much as in Java, but I still use them (specially extracting variables and constants… I use those all the time).

    I searched for an inline method refactoring at least once and I was disappointed not to see it. Well… I’ll bo looking forward to RubyMine 4 then!

  2. Pingback: RubyMine 4.0 Beta is Available for Download! | JetBrains RubyMine Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>