Skip to content

Release Note 2.7

Soutaro Matsumoto edited this page Oct 7, 2022 · 7 revisions

RBS 2.7.0 is the latest version of RBS 2.7.

Some of the highlights in RBS 2.7 are:

  • Self type bindings in procs and blocks (#1077)
  • RDoc plugin (#1048)

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

gem 'rbs', '~> 2.7.0'

See the CHANGELOG for the details.

You can upgrade RBS 2.6 in Ruby programs safely without any modification.

Self type bindings in procs and blocks

See #1077 for the detail.

Some Ruby methods like #instance_eval evaluates the block with self other than outside of the block.

123.instance_eval do
  # self is `123`, not the toplevel object
end

The feature is frequently used in DSL definitions, or .scope method in ActiveRecord::Base is one of the most frequently seen examples of the feature.

RBS 2.7 introduces a new syntax to declare a block is evaluated under different self:

class Foo
  def foo: () { () [self: String] -> void } -> void
end

The [self: String] is the self type binding of a block of method #foo. The implementation would look like the following:

class Foo
  # foo receives a block, and it evaluate with self that is a String
  def foo(&block) = "hello".instance_eval(&block)
end

RDoc plugin

RBS 2.7 provides a RDoc plugin that reads RBS files and generates RDoc.

$ bundle exec rdoc sig

This is preliminary implementation of the RDoc support. It lacks many important features -- supporting generic classes, generating interface & type alias docs, ...

Acknowledgement: This is a work by a contributor supported by Google Summer of Code 2022.

Signature updates