# Sorbet

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

> **TL;DR**
> Add the `sorbet` and `sorbet-runtime` gems to your `Gemfile` and [install them to your project interpreter](using-the-bundler.html#install_gems_local).

RubyMine can infer many types directly from Ruby code. For example, it recognizes a string literal as `String` and determines that `String#length` returns `Integer`.

When a type cannot be inferred reliably, RubyMine can use [Sorbet](https://sorbet.org/) type signatures. You can declare signatures inline in Ruby code by using `sig`, or store them separately in `.rbi` files. RubyMine uses type information from both sources to determine the types of parameters, return values, variables, and expressions.

Procedure: Add type signatures

* To declare a signature directly in Ruby code, extend `T::Sig` and add a `sig` declaration before the method:

```RUBY
# typed: true

module MyFoo
  class Bar
  end

  class Service
    extend T::Sig

    sig { params(foo: MyFoo::Bar).returns(MyFoo::Bar) }
    def process(foo)
      foo
    end
  end
end

service = MyFoo::Service.new
result = service.process(MyFoo::Bar.new)
```

The signature declares that `process` accepts and returns an object of type `MyFoo::Bar`. RubyMine can therefore determine the types of `foo`, the method call, and `result`.

* To keep the Ruby implementation free of Sorbet annotations, declare the corresponding types in a separate `.rbi` file:

```RUBY
# typed: true

module MyFoo
  class Bar
  end

  class Service
    sig { params(foo: MyFoo::Bar).returns(MyFoo::Bar) }
    def process(foo); end
  end
end
```

An explicit `# typed:` sigil is required. You do not need to add `extend T::Sig` to a declaration.

Procedure: View the type info

1. Place the caret within the expression whose type you want to inspect. Then select `View | Type Info` or press `Ctrl+Shift+P` (Windows), `⌃ ⇧ P` (macOS), `⌃ ⇧ P` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+P` (XWin), `Ctrl+Shift+P` (GNOME), `Ctrl+Shift+P` (KDE), `Ctrl+Shift+P` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌃ ⇧ P` (Sublime Text (macOS)), `Ctrl+Shift+P` (Visual Studio), `Ctrl+Shift+P` (Visual Studio (macOS)), `Ctrl+Shift+P` (TextMate), `Ctrl+Shift+P` (NetBeans), `Ctrl+Shift+P` (Eclipse), `Ctrl+Shift+P` (Eclipse (macOS)).

2. If several expressions are available at the caret position, RubyMine displays an expression chooser. Select the expression for which you want to view type information.

![Choosing an expression](https://resources.jetbrains.com/help/img/idea/2026.3/rm_choosing_expressions.png)

> **Tip:**
> To skip the expression chooser and inspect a particular object directly, select its expression or variable name before invoking `View | Type Info`.

> **Note:**
> Type Info applies to expressions and variables. A method name in a declaration, such as `process` in `def process(foo)`, is not an expression. Invoking Type Info on it displays `No expression found`.

The following example shows type information obtained from a `sig` declaration written directly in Ruby code:

![Viewing type information from an inline Sorbet signature](https://resources.jetbrains.com/help/img/idea/2026.3/rm_view_type_info_inline_sig.png)

The following example shows type information obtained from a signature stored separately in an RBI file:

![Viewing type information from a separate RBI file](https://resources.jetbrains.com/help/img/idea/2026.3/rm_view_type_info_rbi.png)

Procedure: Check that the types match

* RubyMine warns you when a method argument or return value does not match its Sorbet signature. In the following example, the `Greeting#greet` method expects an instance of `User`:

```RUBY
module InspectionExample
  class User
  end

  class Greeting
    extend T::Sig

    sig { params(user: User).void }
    def greet(user)
      puts "Hello!"
    end
  end
end

greeting = InspectionExample::Greeting.new
greeting.greet("Ruby")
```

The call passes a `String` instead of the required `User`. RubyMine highlights `"Ruby"` and reports: `Expected type 'User', got 'String' instead`.

You can manage these warnings using the  Mismatched argument type  and  Mismatched return type  [inspections](code-inspection.html).

![String argument that does not match the expected User type](https://resources.jetbrains.com/help/img/idea/2026.3/rm_sorbet_incompatible_types.png)

## Navigate between Ruby and RBI files

RubyMine enables you to navigate from a Ruby declaration to its type signature and from an RBI signature to its associated Ruby declaration.

Procedure: Go to the type signature

* Select a Ruby declaration and go to `Navigate | Type Signature` in the main menu.

![Navigate to an RBI file](https://resources.jetbrains.com/help/img/idea/2026.3/rm_navigate_to_rbi.animated.gif)

Procedure: Go to the associated Ruby declaration

* Select a type signature and go to `Navigate | Associated Declaration` in the main menu.

![Navigate to the associated Ruby declaration](https://resources.jetbrains.com/help/img/idea/2026.3/rm_navigate_from_rbi_to_rb.animated.gif)

> **Tip:**
> These actions do not have default shortcuts. If you use them frequently, consider assigning your own shortcuts.
>
>
>
> 1.    In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Meta+Comma` (TextMate), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), select  Keymap .
>
> 2.  Find the `Go to Type Signature or Associated Declaration` action using the search field. Double-click the action to assign a shortcut.

