RubyMine 2023.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 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.

If you need to undo your refactoring, press Control+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 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: 27 February 2023