TL;DR

T-Ruby is an experimental compiler that lets developers write Ruby with inline type annotations (.trb) and emits plain Ruby (.rb) plus RBS type signatures. It avoids runtime type gems, integrates with editors and type-checking tools, and is open source.

What happened

A new project called T-Ruby introduces a file format and compiler that embed type annotations directly in Ruby source using a TypeScript-like syntax. Source files with the .trb extension include inline type signatures on method parameters and returns; the T-Ruby compiler then generates plain .rb files (standard Ruby without runtime type code) and accompanying .rbs signature files. The project publishes example code showing simple methods (greet and add) typed and compiled into untyped Ruby plus RBS entries. Installation and workflow notes in the project documentation show a gem-based install (gem install t-ruby), a project initializer (trc –init) and a watch mode (trc –watch). The maintainers position T-Ruby as RBS-compatible, editor- and tool-friendly, and explicitly label the project experimental while inviting contributions on GitHub.

Why it matters

  • Inline types let Ruby source carry type intent without inserting runtime checks or DSL boilerplate.
  • Automatic generation of RBS files can bridge typed source and existing Ruby tooling that consumes signatures.
  • Tooling integrations (editors, LSP, type checkers) aim to make typed development fit into current Ruby workflows.
  • If successful, the approach may simplify adopting static types in Ruby projects without runtime dependencies.

Key facts

  • T-Ruby uses .trb input files that contain inline type annotations on methods.
  • The compiler generates standard .rb files and corresponding .rbs signature files.
  • Example: def greet(name: String): String in .trb becomes an untyped def greet(name) in .rb and a typed entry in .rbs.
  • Install and start: gem install t-ruby; trc –init to initialize; trc –watch for watch mode.
  • Project claims compatibility with the Ruby ecosystem, stating RBS compatibility and support for any Ruby version.
  • Editor integrations listed: VS Code extension, JetBrains plugin, Neovim plugin, plus a Language Server (LSP).
  • Type checker integrations mentioned: Steep, Ruby LSP, and Sorbet (via generated RBS).
  • The project is open source, hosted on GitHub, and described as experimental with the core compiler working.

What to watch next

  • Progress toward stability and expanded feature completeness, since the project is currently experimental.
  • Maturity and feature coverage of the editor plugins and LSP implementation (not confirmed in the source).
  • Depth of interoperability with external type checkers and ecosystems beyond initial RBS generation (not confirmed in the source).
  • Broader community adoption and production usage patterns (not confirmed in the source).

Quick glossary

  • RBS: A Ruby signature format used to describe method and class type information separately from implementation.
  • LSP (Language Server Protocol): A protocol that lets editors provide language features like completion and diagnostics via a language server.
  • Static type checker: A tool that analyzes source code for type correctness without running the program.
  • Gem: A packaged library or tool for Ruby distributed via RubyGems, installable with the gem command.

Reader FAQ

Does T-Ruby require a runtime type library?
No. The project states it generates standard Ruby without runtime type dependencies.

What files does T-Ruby produce?
It produces plain .rb files and corresponding .rbs signature files from .trb inputs.

How do I try T-Ruby?
The docs list gem install t-ruby, use trc –init to set up a project, and trc –watch to run the compiler.

Is T-Ruby production-ready?
The project is described as experimental; the core compiler works but requires further improvements.

Does T-Ruby replace Sorbet or other type systems?
Not confirmed in the source.

Example Write typed Ruby, compile to standard Ruby with generated type signatures. hello.trb INPUT # hello.trb def greet(name: String): String "Hello, #{name}!" end def add(a: Integer, b: Integer): Integer a…

Sources

Related posts

By

Leave a Reply

Your email address will not be published. Required fields are marked *