Working With RBS in RubyMine
Starting with v2021.2, RubyMine provides code assistance for working with RBS files, along with all of the essential features that make RBS code easier to read. Here’s a brief overview.
Do you prefer video tutorials instead? In that case, check out our Get started with RBS video.
Creating RBS code
- Generate RBS type signatures using the Generate Code popup (⌘N or Alt+Insert).
- Run RBS commands with Run Anything (double ^ or double Ctrl).
- Use file templates to create new RBS files, classes, modules, or interfaces.
- Create your own RBS live templates to insert frequently-used constructions into your code.
- Code completion now works for RBS code and includes suggestions for classes, modules, methods, keywords, and more.
Formatting and readability
- Syntax highlighting, code folding, and formatting.
- Smart indentation, auto-insertion of parentheses, and the end keyword.
- Commenting with a shortcut (⌘/ or Ctrl+/ ) and automatic continuation of comments.
- Structure view for RBS files (⌘7 or Alt+7).
- You can now navigate between corresponding
.rbsfiles using new navigation actions. Right-click a project entity, like a class or a method, and select Go to | Type Signature | Associated Declaration. You can also use the ⌃⌘↑ (Ctrl+Alt+Home) shortcut.
- Partial declarations in RBS files are now marked with gutter icons. You can navigate between them by clicking on these icons.
- The Rename refactoring now works within RBS files. For simple refactorings, RubyMine uses the inline version, while in complex cases RubyMine will show a popup. The refactoring accepts names without prefixes, so there is no need to write
@@, for interfaces, global variables, and instance/class variables respectively.
- If you rename an element in RBS, the IDE will automatically try to find and rename text occurrences in comments and string literals.
- RubyMine checks the syntax of RBS files, and if there’s an error, shows what is expected instead.
- A couple of new inspections specific to RBS: unresolved references, and the presence of singleton methods or modules in interfaces.
Support for RBS was first introduced in RubyMine 2021.1 and improved in v2021.2.
To start using RBS in RubyMine, you will need to have the rbs gem in your project. It comes bundled with Ruby 3.0.0 (or later), but needs to be manually installed for earlier Ruby versions (Ruby 2.6.0 and later).
Lastly, check out our post about the benefits of taking the time to add RBS declarations to your project: RBS: How to Get the Most Out of RubyMine’s Code Assistance.
The RubyMine team
Subscribe to Blog updates
Thanks, we've got you!
Collaborative Programming in RubyMine
Hi everyone, We're back with a new how2pro blog post unveiling another cool RubyMine feature – the Code With Me plugin. When you're knee-deep in a complex task or tangling with an issue that's testing your limits, having someone by your side can make all the difference. Additionally, in an educati…
RBS: How to Get the Most Out of RubyMine’s Code Assistance
The following article shows the benefits of investing some of your time into adding RBS declarations to your project. Catch type errors RubyMine performs real-time type checking based on the information stored in .rbs files. It will show a type error if there’s a mismatch between the RBS and Ruby co…
How to Run Ruby/Rails Commands from the IDE instead of the Terminal
In the Ruby/Rails community, using a terminal is the most popular way to perform various commands and tasks. These tasks include running scripts, tests, Rails generators, Git and Docker commands, and many other things. We also noticed this ourselves when we did some RubyMine usability testing among …
Find usages in RubyMineEarly Access Program
To get the most recent information about Searching for usages in RubyMine, refer to the Search for usages topic. Find usages can be used to find all the pieces of code referencing a specific element, such as a class, method, symbol, or many of the others. RubyMine can also find dynamic usages, in…