RubyMine: Code Insight for Ruby and Rails

Artem Sarkisov
Artem Sarkisov

This article was sponsored by JetBrains. Thank you for supporting the partners who make SitePoint possible.

If you are developing in Ruby or Rails, you may have heard of RubyMine.

RubyMine is an IDE for Ruby and Rails developed by JetBrains. It’s been around for almost 10 years and has a huge user base. And yet, as we visit industry events and shows, we often get the question: “Okay, what does RubyMine do that a text editor can’t?”. By no means am I trying to diminish the value or usefulness of free code editors, but “let’s just say, there’s a lot!” is my usual response as I fire the IDE for a quick demo. In this post I’d like to tell you about the key thing that makes RubyMine stand out: Code Insight.

Code Insight includes things like smart code completion, code navigation, language-specific inspections with quick-fixes, smart notifications, and in-editor quick documentation. So many terms, but what do they do and why would you need them? Let me have your attention for five minutes before you switch back to your $EDITOR$ and get on with your work.

Automatic Code Completion

This feature doesn’t need any introduction as it exists in all the popular editors. However, RubyMine’s autocompletion is not limited to Ruby/Rails built-in keywords and text-based autocompletion. As the IDE indexes your whole project on each startup, it can autocomplete almost any relevant entity regardless of where it’s defined. You don’t need to open a file in a separate tab to autocomplete any declarations from it – RubyMine knows everything about your project already!

Say, you are creating a new table. RubyMine will suggest possible autocompletion options of relevant column types and properties as you’d expect:

RubyMine - creating a new table

But wouldn’t you like to have access to the columns later, when you are working on a model? Of course you would, and the IDE will do that for you the same way as it autocompletes all the built-in Rails stuff:

RubyMine - IDE autocompletes

How about the ability to also autocomplete methods, earlier defined in the model, say, in controllers or other ruby files in your project? You got it:

RubyMine autocomplete methods

The IDE won’t make autocomplete suggestions for column names where you are expecting to see methods defined in the given model, and vice versa. This is a very important feature that makes the RubyMine completion stand out from other editors.

You can work with your views in the same manner. I am not talking about just the basic HTML and ERB syntax suggestions, they are a given, but actually all the specified entities in your project:

RubyMine - work with your views

Go to declaration (aka Go to definition)

When I talk with our customers, I always ask them what their favorite RubyMine feature is. The top reply of all time is “Go to declaration rocks!”. While I’d rather hear success stories about our GUI debugger or other advanced features, positive feedback is always good! But I got curious as to why this happened time and time again, so eventually I started comparing RubyMine’s Go to declaration with Go to definition that exists in some popular editors.

Without a doubt, the IDE proved to be far more reliable when navigating to declarations. Just use ⌘+Click | Ctrl+Click (or ⌘+B | Ctrl + B if you put your caret on the desired object) and jump to the definition you need:

RubyMine - Go declarations

Not only can you easily jump to a class, method, or any other entity declaration in your project, but you can also navigate to gems and their entities’ definitions. Need to rewrite a bit of Ruby on Rails to make your project better? Say no more:

RubyMine - Go to declaration rewrites

I tried to find some plugins that could do the same for the code editors I’ve been checking out lately, but they haven’t helped much. If you know some, your suggestions in the comments would be much appreciated. But until then, I’m sticking with my story: Go to declaration alone should make you want to give RubyMine a shot!

Static Analysis

What I love about Atom is its solid syntax highlighting. It won’t let me miss a closing tag or end. I also discovered a great plugin that underlines all RuboCop offenses and even allows you to autocorrect offenses for the file. Kudos, Atom and the plugin creator, this is cool!

Until recently, I’d say this kind of RuboCop support is as good as the one we have in RubyMine. But with the latest release of RubyMine 2017.3, you are now not only able to fix the whole file with RuboCop, but even choose whether you want to autocorrect all possible offenses, a specific cop department, or even a particular offense type. You get all of this out of the box, right from the editor, and just by pressing Alt+Enter:

RubyMine - static analysis

As for syntax checking, RubyMine is surely smart enough to provide basic syntax highlighting for Ruby, Rails, JavaScript, HTML, CSS, ERB, and more. On top of that, the IDE has a number of its own helpful intentions, like the ability to convert do … end blocks to {}, or modify statements to trailing conditionals. Find and apply these via the same Alt+Enter:

RubyMine - syntax checking

By the way, apart from static analysis, but in terms of intention actions, RubyMine even provides a built-in RegExp checker:

RubyMine built in RegExp checker

As you would expect, these and other inspections and intentions can be found and easily enabled or disabled in the settings.

Yet another Code Insight goodie is Parameter name hints. As you might guess from its name, it helps you understand the name of the argument you are passing to a method:

RubyMine parameter name hints

A great alternative to param name hints is Parameter info which can be triggered by pressing ⌘+P | Ctrl+P. For example, this may be helpful if you realize that inline hints irritate you too much and you decide to turn them off, but at some point need to check out the param names you’ve declared:

RubyMine parameter info

Smart notifications and actions

As another trademark feature of all JetBrains IDEs, RubyMine provides smart notifications that help users never forget about routine tasks, like configuring detected data sources, or running bundle install after adding a new gem to the Gemfile.

There are more multiple-stage smart actions that can come in handy. For example, RubyMine has a shortcut for quick navigation between a Rails entity, e.g. a controller, and its test (Shift+⌘+T | Ctrl+Shift+T). If such a test doesn’t exist, RubyMine will suggest creating it based on the test framework you have installed. But what if you don’t have any test framework yet? In this case RubyMine will add a required gem to the Gemfile, install it for you, and then navigate you to the newly created controller test:

RubyMine shortcut from Rails entity to test

Speaking of Rails entities, you can also navigate to related Rails symbol with ⌃⌘↑ / Ctrl+Alt+Home.

Quick Documentation

Finally, RubyMine provides in-editor quick documentation for built-in Ruby/Rails entities, as well as entities declared in the app. This means you don’t need to surf the web each time you stumble across some alias, or search your whole app for a method declaration you can’t remember. Just put the caret on a keyword you want to look up, and hit F1. The best part is that it also works from the autocompletion list:

RubyMine quick documentation

The above-mentioned abilities cover the stack of Code Insight features in RubyMine, but there are many more features to love in the IDE: safe refactorings, a GUI-based debugger and testing suites, and a range of navigation abilities. Check out our website to learn more about them all.

If you find any of these worth trying, go ahead and download RubyMine and use it free for a month. If your whole dev team would like to try RubyMine, you can also apply for an extended 90-day trial.

Finally, don’t forget to check if you qualify for a discounted license: OSS projects and students can apply for free JetBrains licenses, and startups may get a 50% discount!

Happy developing!

Frequently Asked Questions about RubyMine Code Insight for Ruby and Rails

What are the key features of RubyMine Code Insight?

RubyMine Code Insight is a powerful tool that offers a range of features designed to enhance your coding experience. It provides smart coding assistance, which includes on-the-fly error checking and code quality inspection. It also offers intelligent code completion, which suggests the most relevant options for your current context. RubyMine Code Insight also supports a variety of testing frameworks, including RSpec, Cucumber, and Test::Unit, allowing you to develop robust and reliable code. Additionally, it provides a unified UI for working with Git, GitHub, Mercurial, and other version control systems.

How does RubyMine Code Insight improve code quality?

RubyMine Code Insight improves code quality by providing on-the-fly error checking and code quality inspection. It highlights errors as you type and suggests quick-fixes to resolve them. It also checks your code against several code quality standards and provides suggestions to improve it. This helps you to maintain a high standard of code quality and reduces the likelihood of bugs and errors in your code.

Can I use RubyMine Code Insight for Rails development?

Yes, RubyMine Code Insight is fully equipped for Rails development. It provides specific coding assistance for Rails, including code completion, navigation options, and automated refactorings. It also offers a dedicated Rails project view and quick navigation between MVC components. This makes it a powerful tool for Rails development.

How does RubyMine Code Insight support testing?

RubyMine Code Insight supports a variety of testing frameworks, including RSpec, Cucumber, and Test::Unit. It provides a unified interface for running tests and viewing results, making it easy to develop robust and reliable code. It also offers code coverage tools, allowing you to see how much of your code is covered by tests.

How does RubyMine Code Insight integrate with version control systems?

RubyMine Code Insight provides a unified UI for working with various version control systems, including Git, GitHub, Mercurial, and others. It allows you to perform common version control tasks directly from the IDE, such as committing changes, creating branches, and resolving conflicts. This makes it easy to manage your codebase and collaborate with others.

Is RubyMine Code Insight suitable for beginners?

Yes, RubyMine Code Insight is suitable for beginners. It provides a range of features designed to make coding easier and more efficient, including smart coding assistance, intelligent code completion, and on-the-fly error checking. It also offers extensive documentation and tutorials to help beginners get started.

Can I customize RubyMine Code Insight to suit my coding style?

Yes, RubyMine Code Insight is highly customizable. You can adjust the IDE’s appearance, behavior, and keymap to suit your preferences. You can also customize the code style settings, including indentation, spaces, and wrapping and braces.

How does RubyMine Code Insight help with debugging?

RubyMine Code Insight provides a powerful debugger with a user-friendly interface. It allows you to set breakpoints, step through your code, and inspect variables. It also offers a range of debugging tools, including an interactive console, a variables view, and a call stack view.

Does RubyMine Code Insight support database tools?

Yes, RubyMine Code Insight supports a range of database tools. It provides a unified interface for managing your databases, allowing you to create, modify, and analyze data directly from the IDE. It also supports a variety of SQL dialects, making it easy to work with different databases.

Can I use RubyMine Code Insight for other languages besides Ruby?

Yes, while RubyMine Code Insight is primarily designed for Ruby and Rails development, it also supports a variety of other languages, including JavaScript, CoffeeScript, ERB, HAML, LESS, Sass, and more. This makes it a versatile tool for multi-language development.