Built with 💜 at Stripe.
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.
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.
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.
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
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
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.
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.
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.
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.
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.