Typed Ruby

RBS has its own syntax for defining Ruby types. The definitive source for the syntax reference is found at https://github.com/ruby/rbs/blob/master/docs/syntax.md. We’ll go over the structure here.

RBS Declarations and File Structure

RBS syntax has a few main parts (we’re adopting the naming convention from the official syntax file):

  • Declarations are class, module, and interface structures that can be used as types in other parts of the file.

  • Members are things that are inside declarations that might have type information, including instance variables, attributes, and methods.

  • Types are the things that RBS uses to specify actual type information, including class names, union of class names, or literal types, as well as a few RBS-specific ...

Get Programming Ruby 3.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.