Learn RubyMine

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.

Creating RBS code

  • Generate RBS type signatures using the Generate Code popup (⌘N or Alt+Insert).
    Generate type signatures
  • Run RBS commands with Run Anything (double ^ or double Ctrl).
    Run RBS commands with Run Anything
  • Use file templates to create new RBS files, classes, modules, or interfaces.
    RBS file templates
  • Create your own RBS live templates to insert frequently-used constructions into your code.

Code completion

  • Code completion now works for RBS code and includes suggestions for classes, modules, methods, keywords, and more.
    Code completion for RBS

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).
    Formatting RBS files
  • You can now navigate between corresponding .rb and .rbs files 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.
    Navigation between .rb and .rbs files
  • Partial declarations in RBS files are now marked with gutter icons. You can navigate between them by clicking on these icons.
    Navigation between partial declarations in RBS files

Refactoring

  • 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 _, $, @, and @@, for interfaces, global variables, and instance/class variables respectively.
    Inline rename
  • If you rename an element in RBS, the IDE will automatically try to find and rename text occurrences in comments and string literals.
    Rename a text occurrence in an RBS file

Inspections

  • RubyMine checks the syntax of RBS files, and if there’s an error, shows what is expected instead.
    RBS syntax error
  • A couple of new inspections specific to RBS: unresolved references, and the presence of singleton methods or modules in interfaces.
    RBS: unresolved reference error

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.7.0 and later).

Check out our documentation to learn more about RBS support in RubyMine. As always, please don’t hesitate to report any issues you encounter.


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.

Happy developing!
The RubyMine team

Discover more