Use the Extract Module refactoring to create a module from the methods and constants of a Ruby class. As a result of this refactoring, methods are extracted into modules, and replaced with the include or extend statements, depending on the selected context.
To extract module from a class
- Open the desired class in the editor.
- On the main menu, or on the context menu of the editor, choose .
- In the Extract Module dialog box, provide the following information:
- Name of the new module.
- Target directory where it will be stored.
- Context (instance or static) to form the new module.
- Methods to be included in the new module. Note that static methods are disabled for the instance context, and vice versa.
- Click OK. The new module is created in the specified directory, and the source class is updated accordingly:
requirestatement is added.
- Extracted code is replaced with the reference to the new module.