Skip to content

Latest commit

 

History

History
69 lines (48 loc) · 1.97 KB

overview.md

File metadata and controls

69 lines (48 loc) · 1.97 KB
id title
overview
Overview

Type checking with Sorbet is composed of two key components:

  • srb

    This is the command-line interface to Sorbet. It includes the core type checker, which analyzes a project statically (before the code runs) to report potential mistakes in the code. It also contains utilities to set up a project to work with Sorbet for the first time.

  • sorbet-runtime

    This is the gem that enables adding type annotations to normal Ruby code. It exposes the top-level T namespace and the sig method, which we'll see more of in Signatures. It also dynamically type checks the code while it runs.

These two components are developed in tandem, and in fact compound each others' guarantees. Sorbet makes predictions about the runtime, and the runtime enforces those predictions with contracts.

Here's a taste of what Sorbet can do:

# typed: true
require 'sorbet-runtime'

class A
  extend T::Sig

  sig {params(x: Integer).returns(String)}
  def bar(x)
    x.to_s
  end
end

def main
  A.new.barr(91)   # error: Typo!
  A.new.bar("91")  # error: Type mismatch!
end
→ View on sorbet.run

What's next?