Generate code
Code | Generate or AltInsert
Configure: CtrlAlt0S Settings | Editor | File and Code Templates
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 (<% %>).
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_add_paired_element.png](https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_add_paired_element.png)
To enable or disable whether to add closing elements, open the Settings dialog CtrlAlt0S, click General under Editor, and then Smart Keys. For example, you can use the following options:
Insert pair brackets
Insert pair quote
You can generate an empty stub for a method that you want to use but have not yet defined.
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_method_from_usage.png](https://resources.jetbrains.com/help/img/idea/2024.3/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 AltEnter, choose the Create method '<name>' from the suggestion list, and press Enter.
RubyMine lets you quickly add accessor methods for instance variables using the attr_reader, attr_writer, and attr_accessor attributes.
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_attribute.png](https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_attribute.png)
To do this, perform the following steps:
Place a caret inside a class and press AltInsert.
In the popup that opens, select Reader, Writer, or Accessor.
Choose the required instance variable in the invoked dialog and click OK.
tip
Note that if you create the variable’s Accessor after creating the Reader, RubyMine will replace a corresponding attr_reader with attr_accessor automatically.
You can override any method of a parent class by generating the corresponding method stub in a child class.
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_override_method.png](https://resources.jetbrains.com/help/img/idea/2024.3/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 (Ctrl0O).
On the Code menu, click Generate (AltInsert) and select Override methods.
Choose the desired method in the Select Methods to Override dialog.
Implement the created method.
tip
Use the
button in the left gutter to open the overridden method declaration.
RubyMine lets you quickly unwrap or extract expressions from enclosing statements.
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_generate_code_unwrap.png](https://resources.jetbrains.com/help/img/idea/2024.3/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 CtrlShiftDelete. RubyMine shows a popup with all the actions that are available in the current context.
Click the desired action and press Enter.
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.
![https://resources.jetbrains.com/help/img/idea/2024.3/rm_live_templates_example.png](https://resources.jetbrains.com/help/img/idea/2024.3/rm_live_templates_example.png)
For more information, refer to Live templates.
Thanks for your feedback!