RubyMine 2020.2 Help

Code Style. Ruby

File | Settings | Editor | Code Style | Ruby for Windows and Linux

RubyMine | Preferences | Editor | Code Style | Ruby for macOS Ctrl+Alt+S the Settings/Preferences icon

Use this page to configure code style options for Ruby files. When you change these settings, the Preview pane shows how this will affect your code.

Tabs and Indents

ItemDescription
Use tab character
  • If this checkbox is selected, tab characters are used:

    • On pressing the Tab key

    • For indentation

    • For code reformatting

  • When the checkbox is cleared, RubyMine uses spaces instead of tabs.

Smart tabs
  • If this checkbox is selected, the part of indentation defined by the nesting of code blocks, is made of the tabs and (if necessary) spaces, while the part of indentation defined by the alignment is made only of spaces.

  • If this checkbox is cleared, only tabs are used. This means that a group of spaces that fits the specified tab size is automatically replaced with a tab, which may result in breaking fine alignment.

The Smart Tabs checkbox is available if the Use tab character checkbox is selected.

Tab sizeIn this field, specify the number of spaces included in a tab.
IndentIn this field, specify the number of spaces (or tabs if the Use tab character checkbox is selected) to be inserted for each indent level.
Continuation indentIn this field, specify the number of spaces (or tabs if the Use tab character checkbox is selected) to be inserted between the elements of an array, in expressions, method declarations and method calls.
Keep indents on empty linesIf this checkbox is selected, RubyMine will keep indents on the empty lines as if they contained some code.
If this checkbox is cleared, RubyMine will delete the tab characters and spaces.
Use indents relative to expression start

Use this checkbox to switch between the two possible indentation behaviors:

  • If this checkbox is not selected, the blocks of code will be formatted against the closest ancestor block that starts on a new line.

  • If this checkbox is selected, the blocks of code will be formatted in columns.

Indent methods after access modifiersSelect the public, protected or private checkboxes to create an extra indentation after the corresponding access modifier.

Spaces

Use this tab to specify where you want RubyMine to insert spaces automatically. Select the checkboxes next to the description of relevant locations and check the results in the Preview pane.

Wrapping and Braces

Visual guides

Allows you to specify the position of visual guides that help you control the width of the code. If you want to specify several visual guides, enter numbers separated by a comma, for example, 45, 60.

Visual guides

Keep when reformatting

Use the options to configure exceptions that RubyMine will make when reformatting the source code. By default, the Line breaks checkbox is selected. RubyMine in this case will ignore line breaks when reformatting the source code. If your code contains lines that are shorter than a standard convention, you can convert them by disabling the Line breaks checkbox before reformatting.

List items

Use these options to format multiline code constructs. For example, if Align when multiple is enabled, RubyMine aligns hash items.

options = {:font_size => 10, :font_family => "Arial"}

Assignments and hashes

Use these options to format variable assignments and hash values. For example, if Align right parts is enabled, RubyMine aligns hash values.

options = {:font_size => 10, :font_family => "Arial"}

Chained method calls

Use the options to format multiline chained method calls. For example, the Alignment option allows you to align chained method calls by the initial receiver or leading dots.

  • Leading dots

    @posts = Post.where(author_id: @user.person_id, public: true) .order("created_at DESC") .limit(25)
  • Initial receiver

    @posts = Post.where(author_id: @user.person_id, public: true) .order("created_at DESC") .limit(25)

Empty declarations

Specify how to format declarations of empty classes, methods, and modules.

  • As is

  • Single-line

    def foo; end
  • Multi-line

    def foo; end

Blank Lines

Use this tab to define where and how many blank lines you want RubyMine to retain and insert in your code after reformatting. The results are displayed in the Preview pane.

Keep Maximum Blank Lines In this area, specify the number of extra blank lines to be kept after reformatting.
Minimum Blank Lines

In this area, configure whether to have or not to have extra empty lines after the blocks of import statements and around classes, fields, methods, or functions. In the field next to each option, specify the minimum number of extra blank lines to be left.

In this area, configure whether to have or not to have extra empty lines around top-level blocks and nested selectors. In the field next to each option, specify the minimum number of extra blank lines to be left.

Code Generation

Add parentheses around method arguments Specify whether to add parentheses around arguments of a generated method. For example, this option is in effect for methods generated from usage or overridden method stubs.
Convert {} blocks to do..end by Enter Enable this option to convert {} blocks to do..end automatically by pressing Enter.

Set from...

Click this link to reveal the list of languages to be used as the base for the current language code style. Only the settings that are applicable to the current language are taken. All the other settings are not affected.

This link appears in the upper-right corner of the language-specific code style page, when applicable.

Click Reset to discard changes and return to the initial set of code style settings.

Last modified: 08 May 2020