📱

Read on Your E-Reader

Thousands of readers get articles like this delivered straight to their Kindle or Boox. New articles arrive automatically.

Learn More

This is a preview. The full article is published at news.ycombinator.com.

T-Ruby is Ruby with syntax for types

T-Ruby is Ruby with syntax for types

By thunderbongHacker News: Front Page

Example Write typed Ruby, compile to standard Ruby with generated type signatures. # hello.trb def greet(name: String): String "Hello, #{name}!" end def add(a: Integer, b: Integer): Integer a + b end # hello.rb def greet(name) "Hello, #{name}!" end def add(a, b) a + b end # 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 Initialize project gem install t-ruby trc --init Start watch mode trc --watch Write typed Ruby 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!

Preview: ~253 words

Continue reading at Hacker News

Read Full Article

More from Hacker News: Front Page

Subscribe to get new articles from this feed on your e-reader.

View feed

This preview is provided for discovery purposes. Read the full article at news.ycombinator.com. LibSpace is not affiliated with Hacker News.

T-Ruby is Ruby with syntax for types | Read on Kindle | LibSpace