RubyMine 2022.3 Help

Extract parameter

The Extract Parameter refactoring is used to add a new parameter to a method declaration and to update the method calls accordingly.

The animation below demonstrates how to add a method parameter by extracting a value from a string:

extract parameter

To extract a parameter:

  1. Select a value to refactor or place a caret at a string containing the required value.

  2. From the main menu, select Refactor | Extract/Introduce | Parameter Ctrl+Alt+P.

  3. (Optional) If you place a caret at a place containing several expressions available for extracting, select the required expression and press Enter:

    expressions for extracting
  4. In the invoked dialog, specify the parameter name and type:

    Extract Parameter dialog

    You can use various parameter types such as positional, array, keyword and so on.

  5. Click Refactor.

Example

Before

After

def greet puts "Hello from JetBrains" end greet
def greet(name) puts "Hello from #{name}" end greet("JetBrains")
Last modified: 27 December 2022