Intention Actions in RubyMine
RubyMine provides you with a set of intention actions that can help you to quickly fix code smells, convert statements for better code style, add strings to locale dictionaries, use language injections, and do other handy things simply by pressing Alt+Enter. Let’s review all the basic and new intention actions added in RubyMine 2018.3.
Let’s start with some basic examples:
Below is a two-line statement that uses a ternary operator. You can easily convert it to an `if…end` clause, which is considered preferable for multiline statements. Just put the caret anywhere inside the statement, and press Alt+Enter:
That’s it! Note that you can rollback this change by pressing Alt+Enter again and choosing the other opposite option.
Syntax changes in the newer Ruby versions are another reason you may need to frequently use RubyMine intentions. For instance, you can quickly replace hash rockets with colons when assigning key-value pairs in hashes, to make it look a bit more up-to-date:
Some intentions may even have nothing to do with Ruby or Rails. For example, there’s an intention that will allow you to quickly check regular expressions:
New intentions in RubyMine
Let’s now take a look at some of the fresh intentions added in RubyMine 2018.3.
First of all, we’ve added a De Morgan’s law intention, to help you improve some ugly negations:
Another new intention that allows you to extract block calls to methods:
With v2018.3, you can also quickly insert a missing `end` for classes, modules, and methods:
Finally, you can now quickly flip binary expressions:
Your RubyMine Team
Subscribe to Blog updates
Thanks, we've got you!