Generate code
Complete paired elements
RubyMine can automatically add various closing elements to your code, for example, brackets, quotes, XML and HTML tags, or tags that wrap Ruby code within views (<% %>).
![complete paired Ruby tags](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_add_paired_element.png)
To enable or disable whether to add closing elements, open the Settings/Preferences dialog Ctrl+Alt+S, click General under Editor, and then Smart Keys. For example, you can use the following options:
Insert pair brackets
Insert pair quote
Generate methods from usage
You can generate an empty stub for a method that you want to use but have not yet defined.
![generate method from usage](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_method_from_usage.png)
To do this, perform the following steps:
Type a name that references a non-existent method. RubyMine highlights the reference.
Press Alt+Enter, choose the Create method '<name>' from the suggestion list, and press Enter.
Create attributes
RubyMine lets you quickly add accessor methods for instance variables using the attr_reader, attr_writer, and attr_accessor attributes.
![add attribute](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_attribute.png)
To do this, perform the following steps:
Place a caret inside a class and press Alt+Insert.
In the popup that opens, select Reader, Writer, or Accessor.
Choose the required instance variable in the invoked dialog and click OK.
Override methods of a superclass
You can override any method of a parent class by generating the corresponding method stub in a child class.
![override method of a superclass](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_override_method.png)
Perform the following steps to do this:
Place a caret inside a child class and do one of the following:
On the Code menu, click Override methods(Ctrl+O).
On the Code menu, click Generate(Alt+Insert) and select Override methods.
Choose the desired method in the Select Methods to Override dialog.
Implement the created method.
Surround code fragments with language-specific constructs
RubyMine provides standard templates for surrounding code fragments with various constructs based on the language of the source code. For example, you can wrap your code into the if … end or unless … end conditional statements.
![wrap code into the if statement](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_surround.png)
To surround a block of code:
Select the desired code fragment.
On the Code menu, click Surround With(Ctrl+Alt+T).
Select the necessary surround statement from the list and press Enter.
Unwrap and remove statements
RubyMine lets you quickly unwrap or extract expressions from enclosing statements.
![unwrap the if statement](https://resources.jetbrains.com/help/img/idea/2021.1/rm_generate_code_unwrap.png)
This action is available for:
Ruby
JavaScript
XML and HTML tags
To unwrap or remove a statement:
Place the caret at the expression you want to extract or unwrap.
Choose Code | Unwrap/Remove from the main menu or press Ctrl+Shift+Delete. RubyMine shows a popup with all the actions that are available in the current context.
Click the desired action and press Enter.
Create code constructs using live templates
Live templates can be used to insert frequently-used constructs into your source code, for example, loops, conditions, various declarations, print statements, tags, and so on.
![Live template Ruby](https://resources.jetbrains.com/help/img/idea/2021.1/rm_live_templates_example.png)
To learn more, see Live templates.