The next few Early Access builds will provide even more refactoring improvements.
Now we can pass an alternative `_digest` attribute as a second parameter to every method that uses `authenticated?`: To do this, we select the desired substring and invoke the Extract Parameter option: We’ll also use this substring as a default parameter for those methods that use `authenticated?`, but don’t pass their own `digest`. Let’s now extract the `remember` substring from the string `remember_digest` and pass it as a second parameter to the method `authenticated?`. We can find all methods that use the method `authenticated?` with Show usages ( Cmd+Alt+F7/Ctrl+Alt+F7): Now, when extracting an argument you may also specify its type, provide a default value, make the argument optional, or pass it as a block.įor example, here’s a method named `authenticated?` which takes one parameter: RubyMine 2018.3 EAP features an updated Extract Parameter dialog. There’s still more we could do here (e.g., turn `take_user` into a `before_filter`), but let’s move on to some new refactoring options that have just recently been improved in v2018.3 EAP. So let’s use the Rename refactoring to rename it at the definition and all the method calls ( Shift+F6):Īs you can see, before renaming the method RubyMine finds all of its usages, so that you can review every method call that is about to be renamed. Its name starts with the `get_` prefix, which is not in line with the general style guide. You can review each of the occurrences, or apply the change for all of them at once:ĭone! Now let’s take a look at the definition of the new method.
To recall how refactorings work in RubyMine, let’s extract a piece of code which is repeatedly used by a number of methods, to its own method:Īfter creating the method and replacing the previously used code chunk with the method call, RubyMine will find all the other usages of that code chunk and suggest replacing them with the method call as well. Extract variables and constants from substrings.These options are available through the Refactor this popup, which is accessible by selecting Refactor | Refactor this or pressing ⌃T / Ctrl+Alt+Shift+T. In mere seconds, you can move files, extract code chunks into methods and variables, and rename values across your project.
RubyMine provides a number of refactorings that can help clean up your code quickly.