RubyMine 2018.3 Help

Extract Method

The Extract Method refactoring allows you to extract a specified code fragment into its own method.

To extract a method:

  1. Select a code fragment to refactor or place a caret at a string containing the required code fragment:

    select code for a method extracting
  2. From the main menu, select Refactor | Extract | Method... (Ctrl+Alt+M).

  3. In the Extract Method dialog, specify the method visibility, name and, optionally, parameter names:

    Extract Method dialog
  4. Click OK to finish refactoring:

    extract method

Example

Before

After

class Hello def greet name = "JetBrains" puts "Hello from #{name}" end end

class Hello def greet name = "JetBrains" puts get_greeting(name) end private def get_greeting(name) "Hello from #{name}" end end

Last modified: 6 December 2018

See Also