Rename refactorings allow you to rename symbols , automatically correcting all references in the code.
The following rename refactorings are available in RubyMine:
- Ruby scripts. Renaming in Ruby scripts applies to all symbols and propagates changes to all their usages across the project.
Ruby classes. Results of renaming a Ruby class depends on the place of
invocation and on the containing file name. First, if a Ruby class has been
created from a template, the containing file name matches the
class name. Thus, renaming a Ruby class from the editor results in generating the new file
according to the Ruby naming conventions. If the name of a containing file doesn't match
only the class and its usages are renamed.
Second, if rename refactoring is invoked from the Project tool window, only file name will be changed; the name of the contained class will be left intact.
Components of Rails applications. Renaming in Rails applications
applies to the application elements (classes, controllers, actions, helpers,
tests, views) and their usages. It is advisable to use the
of the Project tool window, or the editor, to rename elements of the Rails applications.
Rename refactoring in Rails applications has certain subtleties mentioned below:
- On renaming an action or a view template, all associated entities are renamed, including tests. However, on renaming a test, its related entities are not renamed.
- When renaming, keep in mind that the new name should meet Rails naming conventions; otherwise the name will not be properly recognized. It means that when you rename, for example, MyController to YourController, you only have to change My to Your, leaving the Controller suffix intact.
- On renaming a controller or view, its usages in an RSpec test will only be renamed if the options Search in comments and strings is enabled.
- 4.5+When renaming Rails models, all usages are renamed too: the underlying files, classes, test classes and fixtures. RubyMine creates a migration with the instruction to rename the corresponding table. When a field in a model is renamed, RubyMine creates a migration with the instruction to rename the corresponding column in a table, and its foreign key, if any.
- 5.0+ Named scopes. So doing, the lines of code where the renamed scope is called as a method, are also renamed.
- 5.0+ SASS selector
Rename Method. The following usages are renamed:
- All calls of the method.
- All overridden/implemented methods in subclasses.
- Rename Field.
- Rename Function.
- Rename Variable.
Rename Parameter. The following usages are renamed:
- All usages of the parameter.
- The corresponding param tag in documentation comment.
- Rename CSS color value.
- Rename File.
- Rename Directory.
- Select the item to be renamed.
- To select a file, click the desired file in the Project tool window.
- To select a symbol in the editor, place the caret at the name of the symbol to be renamed.
- To select a symbol in the Project tool window, make sure that the members are shown, and then click the desired symbol.
- To select a symbol in the Structure view, click the desired symbol in the Structure tool window.
- Choose Shift+F6Shift+F6Shift+F6Shift+F6Shift+F6Shift+F6Ctrl+RShift+Alt+RShift+F6Shift F6Shift F6Shift F6Alt F6. on the main menu or on the context menu of the selection or press
- The subsequent behavior depends on the check box
Enable in-place mode
- If this check box is selected, the suggested name appears right below the symbol in question. You can either accept suggestion, or type a new name. However, if you press Shift+F6Shift+F6Shift+F6Shift+F6Shift+F6Shift+F6Ctrl+RShift+Alt+RShift+F6Shift F6Shift F6Shift F6Alt F6 once more, RubyMine will display the Rename dialog box with more options.
- If this check box is not selected, the Rename dialog box opens immediately.
The set of controls and their names depend on the type of the symbol to be renamed.
- Preview and apply changes.