Skip to content

Release Note 3.5

Soutaro Matsumoto edited this page Jun 1, 2024 · 7 revisions

Some of the highlights in RBS 3.5 are:

You can install it with $ gem install rbs or using Bundler.

gem 'rbs', '~> 3.5.0.pre'

Read the CHANGELOG for the details.


  • RBS 3.5 has many stdlib signature updates. Updating to 3.5 may cause having different type checking results.
  • Using new syntax may cause issues with tools that doesn't support RBS 3.5

Optional record keys

Pull Requests: #1717, #1732

The record keys with ? prefix are optional.

type json = {
  ?id: Integer,
  name: String,
  email: String?

As you can see in types.rbs, the Types::Record type provides three methods.

class RBS::Types::Record
  attr_reader all_fields: Hash[Symbol, [t, bool]]
  attr_reader fields: Hash[Symbol, t]
  attr_reader optional_fields: Hash[Symbol, t]

The #fields only contains required fields, and optional_fields contains optional fields. It means the existing RBS based tools continue working but ignores optional fields.

Untyped function parameters

Pull Requests: #1806

Method type parameters and block parameters can be untyped with (?) syntax.

class Foo
  def dynamic: (?) -> void

There is no type checking on parameters to call/define the method, and developers are responsible to call/define the methods with correct parameters. Note that the method with (?) accepts any blocks.

One of the motivating examples is the scope method in ActiveRecord. It defines methods with given name and the implementation of the method is given as a block (or proc). RBS cannot type check them statically, but we couldn't write the type of the methods correctly.

class ActiveRecord::Base
  def self.scope: (Symbol) { (?) -> void } -> void
                | (Symbol, ^(?) -> void) -> void

Using the (?) parameter, we pass any blocks/procs to the methods while the developers are responsible for keep them consistent with other codebase or the type definition.

Having the new syntax in the RBS file will result in unexpected errors if the RBS based tools don't support the syntax.

Lexer API

Pull Requests: #1829, #1831

Parser.lex method returns the list of tokens from the input, without constructing syntax tree.

tokens = RBS::Parser.lex(source)

The tokens contains all tokens from the source code, including comments and trivia tokens.

You can use the API to implement linters or something that works on comments.