# Generate code

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

> **TL;DR**
> `Code | Generate` or `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Ctrl+N` (TextMate), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS))
>
>
>
> Configure: `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Meta+Comma` (TextMate), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) `Settings | Editor | File and Code Templates`

## 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/2026.3/rm_generate_code_add_paired_element.animated.gif)

To enable or disable whether to add closing elements, open the Settings dialog `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Meta+Comma` (TextMate), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)), 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/2026.3/rm_generate_code_method_from_usage.animated.gif)

To do this, perform the following steps:

Procedure:

1. Type a name that references a non-existent method. RubyMine highlights the reference.

2. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Alt+Enter` (TextMate), `Alt+Enter` (NetBeans), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)), choose the Create method '<name>'  from the suggestion list, and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

## 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/2026.3/rm_generate_code_attribute.animated.gif)

To do this, perform the following steps:

Procedure:

1. Place a caret inside a class and press `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Ctrl+N` (TextMate), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)).

2. In the popup that opens, select Reader, Writer, or Accessor.

3. 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.

## 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/2026.3/rm_generate_code_override_method.animated.gif)

Perform the following steps to do this:

Procedure:

1. Place a caret inside a child class and do one of the following:

* On the Code menu, click Override methods (`Ctrl+O` (Windows), `⌃ O` (macOS), `⌘ O` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ O` (macOS System Shortcuts), `Ctrl+O` (XWin), `Ctrl+O` (GNOME), `Ctrl+O` (KDE), `Ctrl+O` (Emacs), `Ctrl+O` (Sublime Text), `Ctrl+O` (Sublime Text (macOS)), `Ctrl+O` (Visual Studio), `Ctrl+O` (Visual Studio (macOS)), `Ctrl+O` (TextMate), `Ctrl+O` (NetBeans), `Ctrl+O` (Eclipse), `Ctrl+O` (Eclipse (macOS))).

* On the Code menu, click Generate (`Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Ctrl+N` (TextMate), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS))) and select Override methods.

2. Choose the desired method in the Select Methods to Override

dialog.

3. Implement the created method.

> **Tip:**
> Use the ![go to the superclass method](https://resources.jetbrains.com/help/img/idea/2026.3/app.gutter.overridingMethod.svg) button in the left gutter to open the overridden method declaration.

## 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/2026.3/rm_generate_code_unwrap.animated.gif)

This action is available for:

* Ruby

* JavaScript

* XML and HTML tags

To unwrap or remove a statement:

Procedure:

1. Place the caret at the expression you want to extract or unwrap.

2. Choose Code | Unwrap/Remove from the main menu or press `Ctrl+Shift+Delete` (Windows), `⌘ ⇧ ⌦` (macOS), `⌘ ⇧ ⌦` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ ⌦` (macOS System Shortcuts), `Ctrl+Shift+Delete` (XWin), `Ctrl+Shift+Delete` (GNOME), `Ctrl+Shift+Delete` (KDE), `Ctrl+Shift+Delete` (Emacs), `Ctrl+Shift+Delete` (Sublime Text), `⌘ ⇧ ⌦` (Sublime Text (macOS)), `Ctrl+Shift+Delete` (Visual Studio), `⌘ ⇧ ⌦` (Visual Studio (macOS)), `Meta+Shift+Delete` (TextMate), `Ctrl+Shift+Delete` (NetBeans), `Alt+R` (Eclipse), `Ctrl+Shift+Delete` (Eclipse (macOS)). RubyMine shows a popup with all the actions that are available in the current context.

3. Click the desired action and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

## 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/2026.3/rm_live_templates_example.animated.gif)

For more information, refer to [Live templates](using-live-templates.html).

