What’s Mining: Inline Method Refactoring
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.
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
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
Subscribe to Blog updates
Thanks, we've got you!
RubyMine 2023.3 EAP Update
Hello everyone! We’re back with an update on the state of the 2023.3 Early Access Program. You can download the latest EAP build from our website, via the free Toolbox App, or by using snaps for Ubuntu. Here are the biggest highlights of this release: Performance improvements As we me…
The RubyMine 2023.3 Early Access Program Is Open!
Hello everyone, The third RubyMine Early Access Program of 2023 is underway! The key change in the first EAP build is an important indexing optimization. By refactoring our code base, we’ve doubled RubyMine’s indexing speed compared to v2023.1. This is particularly noticeable when working…
Performance Improvements in RubyMine 2023.1
Hello everybody, The new release is fast approaching, so it’s time to unveil the performance enhancements you can expect from RubyMine 2023.1. Faster code completion When developing and supporting RubyMine, we analyze a great load of anonymized usage data. A lot of recent data pointed to the fact t…
RubyMine 2023.1 EAP5 Is Out!
Hello everyone, RubyMine 2023.1 EAP5 is now available! Below you can find the most notable features in this build. We encourage you to try them out and share your feedback in the comments or in our issue tracker. Migration of Ruby code to the Symbol API In order to improve code insight actions such…