-
Notifications
You must be signed in to change notification settings - Fork 238
Release Note 4.0
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.
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
endRBS 4.0 supports instance method definitions, attributes, instance variable declarations, constant declarations, inheritance, and mixins.
See docs/inline.md for the full syntax details.
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
endPRs: #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.)
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
Psychmethods and exception classes - Added
Hash#transform_keysvariant with positional argument - Added extra keyword options for
File#initialize - Fixed
PStoretypes and treated it as a collection - Added
{Module,Proc}#ruby2_keywordssignatures - Fixed
Zlib::GzipWritersignatures - Fixed
String#append_as_bytesto acceptInteger - Added
Comparable::_CompareToZero - Added
Kernel.trace_varandKernel.untrace_var
There are some breaking changes in RBS 4.0 in the library implementation and the type signature language.
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.
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")%a{deprecated} types are removed.
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.
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.