Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rbs

> 编程语言
Open source

The type signature language for Ruby

2.2K stars0 likes0 views
WebsiteGitHub

About

The type signature language for Ruby

RBS

RBS is a language to describe the structure of Ruby programs. You can write down the definition of a class or module: methods defined in the class, instance variables and their types, and inheritance/mix-in relations. It also allows declaring constants and global variables.

The following is a small example of RBS for a chat app.

…

The Target Version

  • The standard library signatures targets the latest release of Ruby. (4.0 as of 2026.)
  • The library code targets non-EOL versions of Ruby. (>= 3.3 as of 2026.)

Installation

Install the rbs gem. $ gem install rbs from the command line, or add a line in your Gemfile.

gem "rbs"

CLI

The gem ships with the rbs command line tool to demonstrate what it can do and help develop RBS.

$ rbs version
$ rbs list
$ rbs ancestors ::Object
$ rbs methods ::Object
$ rbs method Object then

An end user of rbs will probably find rbs prototype the most useful. This command generates boilerplate signature declarations for ruby files. For example, say you have written the below ruby script.

# person.rb
class Person
  attr_reader :name
  attr_reader :contacts

  def initialize(name:)
    @name = name
    @contacts = []
  end

  def speak
    "I'm #{@name} and I love Ruby!"
  end
end

Running prototype on the above will automatically generate

$ rbs prototype rb person.rb
class Person
  @name: untyped

  @contacts: untyped

  attr_reader name: untyped

  attr_reader contacts: untyped

  def initialize: (name: untyped) -> void

  def speak: () -> ::String
end

It prints signatures for all methods, classes, instance variables, and constants. This is only a starting point, and you should edit the output to match your signature more accurately.

rbs prototype offers three options.

  • rb generates from just the available Ruby code
  • rbi generates from Sorbet RBI
  • runtime generates from runtime API (deprecated; see #2841)

Library

There are two important concepts, environment and definition.

An environment is a dictionary that keeps track of all declarations. What is the declaration associated with String class? An environment will give you the answer.

A definition gives you the detail of the class. What is the type of the return value of gsub method of the String class? The definition for String class knows the list of methods it provides and their types.

The following is a small code to retrieve the definition of the String#gsub method.

…

Guides

  • Architecture
  • Core and standard library signature contribution guide
  • Writing signatures guide
  • Stdlib signatures guide
  • Syntax
  • RBS by Example
  • RBS collection
  • Using Data and Struct
  • Releasing a gem with RBS

Community

Here is a list of some places you can talk with active maintainers.

  • Ruby Discord Server (invite link) -- We have rbs channel in Ruby Discord server.
  • ruby-jp Slack Workspace (in Japanese) -- We have types channel in ruby-jp slack workspace.
  • gem_rbs_collection -- We have a repository of third-party RBS type definitions, for the case your dependency doesn't ship with RBS files.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. Releases are cut by the Release gems workflow rather than from a working copy -- see docs/release.md.

C Code Formatting

This project uses clang-format to enforce consistent formatting of C code with a .clang-format configuration in the root directory.

Setup

First, install clang-format:

# macOS
brew install clang-format

# Ubuntu/Debian
sudo apt-get install clang-format

# Windows
choco install llvm

Usage

Format all C source files:

rake format:c

Check formatting without making changes:

rake format:c_check

Editor Integration

For VS Code users, install the "clangd" extension which will automatically use the project's .clang-format file.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/rbs.

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyrubytype-checking

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言