Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ruby (Plugin)

The Ruby emitter generates Sorbet-compatible .rbi type signature files.

Note: This is a plugin emitter. It must be built and installed as a shared library before use.

Quick Start

#![allow(unused)]
fn main() {
#[derive(TypeWriter)]
#[sync_to(ruby)]
pub struct User {
    pub id: String,
    pub name: String,
    pub age: Option<u32>,
}
}

Output (user.rbi):

# typed: strict
# Auto-generated by typewriter v0.5.2. DO NOT EDIT.

class User < T::Struct
  const :id, String
  const :name, String
  const :age, T.nilable(Integer), default: nil
end

Type Mappings

RustRuby/Sorbet
StringString
boolT::Boolean
u32, i64, etc.Integer
f64Float
Option<T>T.nilable(T)
Vec<T>T::Array[T]
HashMap<K, V>T::Hash[K, V]
UuidString
DateTimeTime

Enum Mapping

  • Unit enumsT::Enum with enums do block
  • Complex enums → Sealed module with T::Struct subclasses

Configuration

[ruby]
output_dir = "./generated/ruby"
file_style = "snake_case"

See the full Ruby Emitter documentation for more details.