RubyMine
 
Get RubyMine

Live templates

Last modified: 20 December 2024

Live templates (or code snippets) allow you to insert frequently-used constructions into your code. These can be conditions, blocks, loops, and so on. For example, the animation below shows how to quickly insert the if-else block by using the predefined ife abbreviation.

https://resources.jetbrains.com/help/img/idea/2024.3/rm_live_templates_example.png
Gif

RubyMine provides numerous predefined templates for various languages and frameworks, including Ruby, Rails, RSpec, JavaScript, and so on. If necessary, you can customize predefined templates or add new ones.

There are three types of live templates:

  • Simple templates contain only predefined code. When you expand a simple template, the text is automatically inserted into your source code, replacing the abbreviation.

  • Parameterized templates contain variables that enable user input. When you expand a parameterized template, you can replace variables manually or provide an expression to calculate them automatically.

  • Surround templates wrap a block of the selected code with the text specified by the user.