ship with a feature to support type checkers. • A type de f i nition language RBS and rbs gem. • RBS type de f i nitions of standard libraries. • Several type checkers are available for Ruby. • You choose the best type checker for your projects.
The most widely used type checker for Ruby. A static type checker for Ruby written in Ruby. Infers types in Ruby programs. (Bundled with Ruby 3.) RDL (Je f f Foster) Research project from Tufts University.
conference.talks.push(*talks) conference.each_speaker do |speaker| puts "%s (%s)" % [speaker.name, speaker.email] end Does new method accept a String argument?
conference.talks.push(*talks) conference.each_speaker do |speaker| puts "%s (%s)" % [speaker.name, speaker.email] end Does new method accept a String argument? What is the type of the value of #talks?
conference.talks.push(*talks) conference.each_speaker do |speaker| puts "%s (%s)" % [speaker.name, speaker.email] end Does new method accept a String argument? What is the type of the value of #talks? What is the type of the speaker?
= Conference.new("RubyConf 2020") # conf.talks << talk1 # conf.talks << talk2 # class Conference # The name of the conference. attr_reader name: String # Talks of the conference. attr_reader talks: Array[Talk] def initialize: (String name) -> void # Yields all speakers of the conference. # Deduped, and no order guaranteed. def each_speaker: { (Speaker) -> void } -> void | () -> Enumerator[Speaker, void] end
Stdlib types and Gem types. Written by Used by Stdlib types Ruby committers (community) All Ruby developers Gem types Gem authors, community Gem users App types The developer of the app The developer of the app
it's native type declaration language. Will support RBS too. (Maybe only a subset.) Uses RBS as the primary type language. Reads library types from RBS and generates RBS.
Ruby code. • Matz believes type annotations will be outdated in future and wants no types written in Ruby code. • To keep type checking optional in Ruby. • To support libraries written in C.
of scope of RBS. • We know type checkers need inline type annotations. class Conference extend T::Sig sig do params(name: String).void end def initialize(name:) @name = name @speakers = T.let([], T::Array[Speaker]) class Conference # Method types are in RBS in Steep. def each_speaker(&block) # @type var speakers: Array[Speaker] speakers = [] talks.each do |talk| speakers << talk.speaker end Sorbet Steep
the version directories to make new version • Optimistic version resolution • Incompatible with semantic versioning • Required version 3.2.1 will resolve to 4.2 if there is no better version available
ship with a feature to support type checkers. • A type de f i nition language RBS and rbs gem. • RBS type de f i nitions of standard libraries. • Several type checkers are available for Ruby. • You choose the best type checker for your projects. • https://github.com/ruby/gem_rbs