Extract/Introduce variable
Refactor | Extract/Introduce | Variable
CtrlAlt0V
The Extract Variable refactoring lets you extract a specified value to a corresponding variable. You can use this refactoring for basic Ruby data types (for example, strings, arrays, hashes) and class instances.
The animation below demonstrates how to extract a specific word from a string to a variable:

To extract a variable:
Select a value to refactor or place the caret at a string containing the required value.
In the main menu, go to Refactor | Extract/Introduce | Variable CtrlAlt0V.
(Optional) If you place the caret at a place containing several expressions available for extracting, select the required expression and press Enter:
(Optional) If more than one occurrence of the expression is found, specify whether you wish to replace only the selected occurrence or all the found occurrences with the new variable:
Specify the variable name and press Enter.
Before
puts "Hello from JetBrains"puts "Goodbye from JetBrains"
After
name = "JetBrains"puts "Hello from #{name}"puts "Goodbye from #{name}"
Thanks for your feedback!