Early Access Program Features

Smarter introduce variable refactoring for Ruby

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

image description