RubyMine 2024.1 Help

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

To enable or disable whether to add closing elements, open the Settings 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

To do this, perform the following steps:

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

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

To do this, perform the following steps:

  1. Place a caret inside a class and press Alt+Insert.

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

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

Perform the following steps to do this:

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

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

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

To surround a block of code:

  1. Select the desired code fragment.

  2. On the Code menu, click Surround With (Ctrl+Alt+T).

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

This action is available for:

  • Ruby

  • JavaScript

  • XML and HTML tags

To unwrap or remove a statement:

  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. RubyMine shows a popup with all the actions that are available in the current context.

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

For more information, refer to Live templates.

Last modified: 26 April 2024