Extract method
Refactor | Extract/Introduce | Method
CtrlAlt0M
The Extract Method refactoring allows you to extract a specified code fragment into its own method.
To extract a method:
Select a code fragment to refactor or place the caret at a string containing the required code fragment:
In the main menu, go to Refactor | Extract/Introduce | Method CtrlAlt0M.
In the Extract Method dialog, specify the method visibility, name and, optionally, parameter names:
Click OK to finish refactoring:
Before
class Hello def greet name = "JetBrains" puts "Hello from #{name}" endend
After
class Hello def greet name = "JetBrains" puts get_greeting(name) end private def get_greeting(name) "Hello from #{name}" endend
Thanks for your feedback!
Was this page helpful?