Sorbet

Sorbet

  • Get started
  • Docs
  • Try
  • Community
  • GitHub
  • Blog
Sorbet Logo

Sorbet is a fast, powerful type checker designed for Ruby.

Built with 💜 at Stripe.

Get startedTry it online

Fast and scalable

Sorbet is multithreaded, scaling linearly across cores on your CPU. It checks your types in seconds, giving you feedback as you code.

Get started with Sorbet →

IDE-ready

Sorbet works with your favorite editor to provide IDE features like autocomplete and jump to definition. It’s easy to add to your CI setup.

Try Sorbet online →

Gradual by design

Sorbet works with normal Ruby, so you can keep using your existing toolchain. Add Sorbet types to your codebase one file at a time.

Learn what makes Sorbet gradual →

A taste of Sorbet

Sorbet is 100% compatible with Ruby. It type checks normal method definitions, and introduces backwards-compatible syntax for method signatures.

Explicit method signatures make Sorbet useful for anyone reading the code too (not just the author). Type annotations serve as a tool for understanding long after they're written.

Sorbet is designed to be useful, not burdensome. Explicit annotations are repaid with clear error messages, increased safety, and increased productivity.

# typed: true
extend T::Sig

sig {params(name: String).returns(Integer)}
def main(name)
  puts "Hello, #{name}!"
  name.length
end

main("Sorbet") # ok!
main()   # error: Not enough arguments provided
man("")  # error: Method `man` does not exist

Get started quickly

Sorbet is designed to get you started quickly. Add and install a few gems, initialize Sorbet, and type check your project. Sorbet also knows what's in a project's Gemfile, so it knows how to make or create type definition files for any gems a project uses.

For more information on how to get started with Sorbet, see the Getting Started guide.

# -- Gemfile --

gem 'sorbet', :group => :development
gem 'sorbet-runtime'
# Install the gems
❯ bundle install

# Initialize Sorbet
❯ srb init

# Type check the project
❯ srb tc

Designed to be interactive

Sorbet gives your Ruby development environment IDE-like features, including autocomplete, in-editor documentation, and go to definition. The implementation leverages the Language Server Protocol to be compatible with your favorite editor.

In the time we've spent adopting Sorbet at Stripe, countless people have told us that adding types to existing code or writing new code feels interactive, like pair-programming with the type checker. People ask Sorbet questions, and it responds in seconds—or faster.

GIF of autocomplete in editor
Sorbet is built at Stripe, where the vast majority of code is written in Ruby. We've developed Sorbet to run fast, model Ruby accurately, and power language-aware editor features for hundreds of developers across millions of lines of actual Ruby code.

Who is using Sorbet?

More than just Stripe, Sorbet has been tested by dozens of companies, projects, and individuals including...

ShopifyShopifyCoinbaseCoinbaseChan Zuckerberg InitiativeChan Zuckerberg InitiativeChimeChimeFactorialFactorialFlexportFlexportGrailedGrailedGustoGustoHealthSherpaHealthSherpaHummingbirdHummingbirdInstacartInstacartKickstarterKickstarterMarketplacerMarketplacerPhishSafetyPhishSafetyTaskRabbitTaskRabbitTriumphPayTriumphPayVonageVonageWorkforce.comWorkforce.com

Are you using Sorbet and want to be mentioned here? Email us or send a PR!

Gradual Typing of Ruby at Scale

Link to Sorbet talk video

Much has already been said about Sorbet. Here's a talk we gave at Strange Loop 2018:

Stripe maintains an extremely large and growing Ruby code base with hundreds of developers and millions of lines of code. Continuing to scale development is one of the most critical tasks to maintaining product velocity and the productivity of Stripe engineering.

This talk shares our experience building a type checker, and adopting it in our massive codebase. We start with a discussion of core design decisions we made in early days of the project, and evaluate how they withstood reality of production use.

Dive into the docs

Gradual Type Checking

Sorbet is a gradual type checker, which enables incremental adoption. On the other hand, it’ll be unfamiliar to those expecting a traditional statically typed language.

Learn why gradual is different →

Enabling Static Checks

Sorbet works with 100% of Ruby, but it does not work the same for all Ruby. Developers can opt into more static checks to get even more safety and productivity.

How to enable static checks →

Flow-sensitive Typing

One way Sorbet works to be useful without getting in the way is with control-flow-sensitive typing. Sorbet tracks the effect of control on types, instead of asking for type annotations.

See the power of flow-sensitivity →

Get started · Docs · Try · Community · Blog · Twitter