RubyMine 2023.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 the caret at a string containing the required value.

  2. In the main menu, go to Refactor | Extract/Introduce | Parameter Ctrl+Alt+P.

  3. (Optional) If you place the 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: 04 April 2024