Skip to content

Release Note 4.0

Soutaro Matsumoto edited this page Mar 17, 2026 · 4 revisions

Some of the highlights in RBS 4.0 are:

  • Experimental inline RBS declaration
  • Generics lower bounds T > Object
  • Singleton types with type arguments singleton(T)[S]

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

gem 'rbs', '~> 4.0.0'

Read the CHANGELOG for the details.

Experimental inline RBS declaration

Warning

RBS inline is still experimental and may change in future releases. Not all of the rbs-inline features are supported yet.

RBS 4.0 ships with experimental support for inline RBS type annotations, allowing you to write type information directly in Ruby source files using comments. Instead of maintaining separate .rbs files, you can keep your type information alongside your code.

class Calculator
  # @rbs (Integer, Integer) -> Integer
  def add(a, b) = a + b
end

RBS 4.0 supports instance method definitions, attributes, instance variable declarations, constant declarations, inheritance, and mixins.

See docs/inline.md for the full syntax details.

Generics lower bounds

PRs: #2490

Generic type variables can be bounded with lower bounds, in addition to upper bounds.

class Foo
  # T must be a superclass of String
  def foo: [T > String] (T) -> T
end

Singleton types with type arguments

PRs: #2502

Singleton types singleton(T) can now have a type argument for the new method.

singleton(Array)[Array[String]]     # Type of `Array` but it must allocate `Array[String]`

(This is mainly for Sorbet integration. RBS doesn't provide features other than syntax.)

Signature Updates

Most of the signature updates for Ruby 4.0 were already shipped in RBS 3.10. This release includes additional updates such as:

  • Graduated bundled gems from Ruby 4.0 (cgi, kconv, etc.)
  • Added missing Psych methods and exception classes
  • Added Hash#transform_keys variant with positional argument
  • Added extra keyword options for File#initialize
  • Fixed PStore types and treated it as a collection
  • Added {Module,Proc}#ruby2_keywords signatures
  • Fixed Zlib::GzipWriter signatures
  • Fixed String#append_as_bytes to accept Integer
  • Added Comparable::_CompareToZero
  • Added Kernel.trace_var and Kernel.untrace_var

Upgrade Guide

There are some breaking changes in RBS 4.0 in the library implementation and the type signature language.

RBS::Source class

Two classes -- RBS::Source::RBS and RBS::Source::Ruby -- are introduced for RBS files and Ruby files with inline type declarations. Some APIs in RBS::Environment are changed and you may need to update your code if it directly uses these classes.

Removed deprecated methods

Kernel#Namespace and Kernel#TypeName have been removed (#2480). Use the following replacements:

# Before
Namespace("::Foo::Bar::")
TypeName("::Foo::Bar")

# After
RBS::Namespace.parse("::Foo::Bar::")
RBS::TypeName.parse("::Foo::Bar")

Removed deprecated types

%a{deprecated} types are removed.

Stricter void type validation

The parser now rejects void type in contexts where it is not allowed (#2590). If you have void appearing in type positions other than method return types (e.g., as a type argument or in a union type), you will need to replace it with an appropriate type such as untyped or top.

Stricter self type validation

The self type is now rejected in contexts where it is not meaningful (#2627). If you use self in type positions outside of instance method signatures (e.g., in constant types or class method return types where self is ambiguous), you will need to use a concrete type instead.

Clone this wiki locally