keyboard labs mouse_free_development productivity rubymine

Automated Refactorings in RubyMine

Refactoring is the process of changing the internal structure of code without changing its external behavior. Successful refactorings involve taking very small, sometimes tedious, steps. Fortunately, many refactorings are simple enough to be automated. In this post, we’ll look at automated refactorings in RubyMine on OS X.

Rename

When the name of a variable, method, or class doesn’t explain its purpose, rename it with shift + F6.

rename

Extract Variable

Help explain complex expressions by introducing variables with command + option + V.

extract variable

Extract Method

Move related logic into a separate method with command + option + M.

extract method

Inline Variable or Method

Inline variables and methods that don’t increase clarity with command + option + N

inline method

Additional Refactorings

Less frequently used refactorings, such as extracting a superclass or module, are available from the “Refactor This…” dialog, control + T.

refactor this dialog

Automation Makes a Difference

Refactoring is a significant part of everyday development. It’s the final step in TDD’s mantra of red, green, refactor. We often refactor inherited code to help us better understand it. Automating refactoring encourages more refactoring. If a simple class rename involves ack and sed, then it’s time to upgrade to an IDE.