RubyMine 2016.1 Help

Move Refactorings

On this page:

Move Refactorings: Basics

The Move refactorings allow you to move classes, modules, members, files and directories within a project. So doing, RubyMine automatically corrects all references to the moved symbols in the source code.

The following Move refactorings are available:

  • The Move File refactoring moves a file to another directory.
  • The Move Directory refactoring moves a directory to another directory.
  • The Move Static Member refactoring moves a static method, variable, or constant from one class to another.
  • The Move Class or Module refactoring moves a Ruby class or module to its own class, creates a hierarchy of directories and adds 'require' statement to the source file.

Performing Move Refactoring

To perform a Move refactoring, follow these general steps:

  1. Select the symbol to be moved and do one of the following:
    • On the Refactor menu, or on the context menu, choose Move.
    • Press F6.
    • In the Project tool window, drag the symbol to the new destination.

    The dialog that opens depends on the type of the selected symbol.

  2. Specify the move options according to the type of the item to be moved. See option descriptions in the Move dialog box reference.
  3. Preview and apply the changes.

Moving a File or a Directory to Another Directory

To move a file or directory to another directory, follow these steps:

  1. Select the file or directory in the Project tool window.
  2. Do one of the following:
    • On the main menu, choose Refactor, and then choose Move.
    • On the context menu of the selection, choose Refactor, and then choose Move.
    • Press F6.

    The dialog that opens depends on the type of the selected symbol.

  3. In the To directory field, specify the folder to move the selected file or folder to. Choose an existing folder from the drop-down list or type the full path to the parent folder to be created.
  4. To have the references to the selected file or folder updated according to the refactoring result, select the Search for references check box.

Moving a class/module

To move a class/module into its own file, follow these steps:

  1. In the editor, place the caret at the name of a class/module to be moved, and do one of the following:
    • On the Refactor menu, or on the Refactor context menu, choose Move.
    • Press F6.
  2. In the Move Class or Module Dialog box that opens, specify the following:
    • New module name
    • New file path
    • Path to the directory where the new module will reside.
  3. Click Refactor.

The Move Module refactoring moves a Ruby module to its own class, creates a hierarchy of directories and adds 'require' statement to the source file.

Examples

Create a Ruby file with the name refactoring_sample.rb that contains the following code:

module AModule class AClass1 class AClass2 < AModule::AClass1 end def foo end end end

Example 1

Place the caret at the module name AModule. The following dialog box opens:

ruby_move_module1

Accept defaults and click Refactor. This action results in the following:

  • The directory refactoring_sample is created.
  • Under this directory, the file a_module is created. This file contains the initial source code specified above.
  • The file refactoring_sample.rb now contains the code:
    class Refactoring_Sample require File.expand_path(File.dirname(__FILE__) + '/refactoring_sample/a_module.rb') end

Example 2

Place the caret at the class name AClass1. The dialog box opens:

ruby_move_module2

Accept defaults and click Refactor. This action results in the following:

  • The directory structure refactoring_sample/a_module is created.
  • Under this directory, the file a_class1 is created. This file contains the initial source code specified above.
  • The file refactoring_sample.rb now contains the code:
    class Refactoring_Sample module AModule require File.expand_path(File.dirname(__FILE__) + '/refactoring_sample/a_module/a_class1.rb') end end

See Also

Last modified: 21 July 2016