RubyMine 5.4.0 Web Help

1.1.1+

Rename refactorings allow you to rename symbols, automatically correcting all references in the code.

The following rename refactorings are available in RubyMine:

Examples

BeforeAfter
Renaming Ruby class with the matching file name
MyClass - my_class.rbYourClass - your_class.rb
Renaming Rails method

def
       bar(a,b,c)
       return a * b + c * 123
 end
 def foo
        a = 0
        b = 1
        c = 2
        return bar (a,b,c)
end

def
        do_smth (a,b,c)
        return a * b + c * 123
 end
 def foo
    a = 0
    b = 1
    c = 2
    return do_smth (a,b,c)
end
4.5+Renaming Rails model
Model Library.

The following symbols should be renamed:

  • Class Library
  • Fixture library.yml
  • Test class library_test.rb
  • Test class LibraryTest.rb
  • File library.rb
Model Books.

As a result of performing the Rename refactoring, RubyMine creates a migration. Execute the migration to have the following symbols actually renamed:

  • Class Books
  • Fixture books.yml
  • Test class books_test.rb
  • Test class BooksTest.rb
  • File books.rb
5.0+Renaming a scope and its usages
Class Word
    scope :word_length, lambda {|word_length| where :char_count => word_length}
end

assert_equal 0, Word.word_length(0).size
Class Word
scope :word_length1, lambda {|word_length| where :char_count => word_length}
end

assert_equal 0, Word.word_length1(0).size
                  
To rename a symbol, follow these general steps
  1. 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..
  2. Choose Refactor | Rename on the main menu or on the context menu of the selection or press Shift+F6Shift+F6.
  3. The subsequent behavior depends on the check box Enable in-place mode (Settings | IDE Settings | Editor).
    • 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+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.

    Note

    The set of controls and their names depend on the type of the symbol to be renamed.

  4. Preview and apply changes.

See Also

Reference:

Web Resources: