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
| Rust | Ruby/Sorbet |
|---|---|
String | String |
bool | T::Boolean |
u32, i64, etc. | Integer |
f64 | Float |
Option<T> | T.nilable(T) |
Vec<T> | T::Array[T] |
HashMap<K, V> | T::Hash[K, V] |
Uuid | String |
DateTime | Time |
Enum Mapping
- Unit enums →
T::Enumwithenums doblock - Complex enums → Sealed
modulewithT::Structsubclasses
Configuration
[ruby]
output_dir = "./generated/ruby"
file_style = "snake_case"
See the full Ruby Emitter documentation for more details.