RubyMine 2021.1 Help

Refactor code

Refactoring is the process of modifying source code in order to make it easier to maintain and extend, but without changing its behavior. RubyMine supports various refactoring operations for different programming languages. This topic mostly covers refactorings available for Ruby.

Invoke refactoring

  1. Select an item to refactor. You can select a file/folder in the Project tool window or expression/symbol in the editor.

  2. Press Ctrl+Alt+Shift+T to open a list of refactorings that can be selected.

    refactor this popup

    Alternatively, you can use a keyboard shortcut for a specific refactoring.

If you need to undo your refactoring, press Ctrl+Z.

Preview refactoring changes

For some refactorings, RubyMine lets you preview changes before applying them.

  1. To see potential changes (the list of usages where the refactoring will be performed), click Preview in the Refactoring Preview dialog.

  2. Check the changes that are going to be made in the Find tool window. You can exclude Delete or remove Ctrl+X changes that you consider unnecessary.

    Refactoring Preview window

  3. Click Do Refactor to proceed with the changes.

Configure refactoring settings

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Code Editing.

  2. On the Code Editing page, in the Refactorings section, adjust the refactoring options and click OK.

Refactorings supported in RubyMine

Rename RefactoringsRefactor | RenameShift+F6
Move and Copy RefactoringsRefactor | Move
Refactor | Copy
F6
F5
Introduce VariableRefactor | Extract | VariableCtrl+Alt+V
Extract ConstantRefactor | Extract | ConstantCtrl+Alt+C
Introduce FieldRefactor | Extract | FieldCtrl+Alt+F
Extract ParameterRefactor | Extract | ParameterCtrl+Alt+P
Extract MethodRefactor | Extract | MethodCtrl+Alt+M
Extract SuperclassRefactor | Extract | Superclass
Extract ModuleRefactor | Extract | Module
InlineRefactor | InlineCtrl+Alt+N
Pull Members Up, Push Members DownRefactor | Pull Members Up
Refactor | Push Members Down
Safe DeleteRefactor | Safe DeleteAlt+Delete
Extract PartialRefactor | Extract | Partial
Extract Include FileRefactor | Extract | Extract Include File
Last modified: 19 May 2021