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

This entry was posted in Better Code, Feature, WhatsMining and tagged , . Bookmark the permalink.

One Response to Smarter introduce variable refactoring for Ruby

  1. Refactoring is why I picked RubyMine on the first place. I’m a great believer in refactoring, so anything you do to improve it is very welcome!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>