T-Ruby 是带有类型语法的 Ruby。
T-Ruby is Ruby with syntax for types

原始链接: https://type-ruby.github.io/

## T-Ruby:增强安全性的类型化 Ruby T-Ruby 通过静态类型扩展 Ruby,提供改进的代码安全性和可扩展性。它允许开发者在 `.trb` 文件中编写带有类型注解的 Ruby 代码,然后编译成标准的 `.rb` (Ruby) 和 `.rbs` (Ruby Signature) 文件——确保与现有的 Ruby 生态系统完全兼容。 与其他 Ruby 类型化解决方案(如 Sorbet)不同,T-Ruby 使用类似于 TypeScript 的内联类型,*无需*运行时依赖。这简化了类型声明和类型签名的生成。 T-Ruby 与流行的编辑器(VS Code、JetBrains、Neovim)和类型检查器(Steep、Ruby LSP、通过 RBS 的 Sorbet)集成。虽然仍处于实验阶段,但它旨在为 Ruby 开发者提供无缝且强大的类型化体验,使大型项目更易于管理和可靠。它是一个积极寻求贡献的开源项目。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 T-Ruby 是带有类型语法的 Ruby (type-ruby.github.io) 18 分,thunderbong 发表于 1 小时前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文
ExperimentalGitHub stars

T-Ruby is Ruby

with syntax for types.

Write .trb files with type annotations.

Compile to standard .rb and .rbs files.

Just like TypeScript.

$gem install t-ruby

What is T-Ruby?

Ruby and More

T-Ruby extends Ruby with additional syntax. This means static types and compile time.

A Result You Can Trust

T-Ruby code converts to Ruby and RBS, guaranteeing compatibility with the entire Ruby and RBS ecosystem.

Safety at Scale

Ensure type safety for your Ruby products with T-Ruby. Stay safe even at large scale.

Example

Write typed Ruby, compile to standard Ruby with generated type signatures.

hello.trbInput
# hello.trb

def greet(name: String): String

"Hello, #{name}!"

end



def add(a: Integer, b: Integer): Integer

a + b

end

hello.rbGenerated
# hello.rb

def greet(name)

"Hello, #{name}!"

end



def add(a, b)

a + b

end

+
hello.rbsGenerated
# hello.rbs

def greet: (name: String) -> String



def add: (a: Integer, b: Integer) -> Integer

Existing Methods

Compare with existing Ruby typing solutions and see why T-Ruby is different.

How it works

A static type checker for Ruby developed by Stripe. Uses sig blocks to declare types on methods.

# typed: strict

require 'sorbet-runtime'



class Greeter

extend T::Sig



sig { params(name: String).returns(String) }

def greet(name)

"Hello, #{name}!"

end

end

Limitations

  • Requires runtime dependency (sorbet-runtime gem)
  • Types must be written separately in sig blocks, like comments above function code.
  • Requires learning sig block's unique DSL syntax.

T-Ruby Approach

T-Ruby uses inline types like TypeScript without runtime dependencies, and generates standard RBS files.

Quick Start

1

Initialize project

gem install t-ruby

trc --init

2

Start watch mode

trc --watch

3

Write typed Ruby

src/hello.trb
def greet(name: String): String

"Hello, #{name}!"

end

Works with your tools

T-Ruby integrates seamlessly with the Ruby ecosystem.

Editors

  • VS Code Extension
  • JetBrains Plugin
  • Neovim Plugin
  • Language Server (LSP)

Type Checkers

  • Steep
  • Ruby LSP
  • Sorbet (via RBS)

Ruby Ecosystem

  • RBS Compatible
  • Any Ruby version
  • All gems work

Join the Journey

T-Ruby is an open source project. Your contribution makes a difference.

It's still experimental. The core compiler works, but there's much to improve.

Feedback and suggestions are always welcome!

联系我们 contact @ memedata.com