.. _Extract to Method:

Extract to Method
=================

.. rst-class:: lead

You can easily move a code fragment to a separate new method. This is called **extract method** refactoring. It helps keeping methods shorter and easier to understand.

Select a block of actions and press :kbd:`Ctrl+1`, select :guilabel:`Extract to method` or :guilabel:`Extract to TCM` from the list of quick assist proposals and press :kbd:`Enter`.

.. figure:: ../../images/common/e_quick_assist_extract_to_method_list.png
	:align: center




A new method is created containing the selected code fragment, and the selection is replaced with a method call.

.. figure:: ../../images/common/e_quick_assist_extract_to_method_after.png
	:align: center




.. note::

	Any local variables declared prior to the code fragment you extracted become arguments of the newly created method. 

.. tip::

	You may change the extracted method name in the edit box, right after the extract action is completed.

.. tip::

	You can also **right-click** in the editor and go to **Refactor** > **Extract to method** or **Extract to TCM**.

.. figure:: ../../images/common/e_quick_assist_extract_to_method_menu.png
	:align: center



