Quantcast
Channel: ruby : RubyMine | The JetBrains Blog
Viewing all articles
Browse latest Browse all 75

Smarter introduce variable refactoring for Ruby

$
0
0

Do you use RubyMine’s introduce variable refactoring? You should, actually, as well as many other refactorings RubyMine offers.

RubyMine 2.5 features an improved procedure for introducing variables, fields or constants. You no longer need to select the block you want to create a variable from. Instead RubyMine gives you options.

The code example below could probably be improved a bit by introducing some local variables.

So, we put the caret on the computer_players and invoke Refactor->Introduce Variable. It opens a popup with several options:

While we move through the options RubyMine highlights the expression that will be extracted as a new variable:

Let’s pick the @game.computer_players.first option

RubyMine surely sees that there are several occurrences and suggests to replace them all:

Once we finish, the code looks like below with a new first_player variable. Voila!

This new functionality is available in the latest RubyMine EAP. We’re looking forward to your feedback, as always.

Develop with pleasure,
JetBrains RubyMine team


Viewing all articles
Browse latest Browse all 75

Trending Articles