RubyMine 2023.3 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 Control+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.

    You can also make a multi-caret selection for an extended range of refactoring operations, including Encapsulate Fields, Move Static Members, Extract Delegate, Extract Interface, and Extract Superclass. To utilize this feature, place the caret in each member you want to apply the refactoring to, and the IDE will automatically preselect and check these members in the refactoring dialog.

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

Preview refactoring changes

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

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

  2. In the Find tool window that opens, check the changes that are going to be made. You can exclude Delete or remove Control+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 dialog (Control+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 Refactorings

Refactor | Rename

Shift+F6

Move and Copy Refactorings

Refactor | Move

Refactor | Copy

F6

F5

Introduce Variable

Refactor | Extract | Variable

Control+Alt+V

Extract Constant

Refactor | Extract | Constant

Control+Alt+C

Introduce Field

Refactor | Extract | Field

Control+Alt+F

Extract Parameter

Refactor | Extract | Parameter

Control+Alt+P

Extract Method

Refactor | Extract | Method

Control+Alt+M

Extract Superclass

Refactor | Extract | Superclass

Extract Module

Refactor | Extract | Module

Inline

Refactor | Inline

Control+Alt+N

Pull Members Up, Push Members Down

Refactor | Pull Members Up

Refactor | Push Members Down

Safe Delete

Refactor | Safe Delete

Alt+Delete

Extract Partial

Refactor | Extract | Partial

Extract Include File

Refactor | Extract | Extract Include File

Last modified: 10 January 2024