T-Ruby v0.0.42 Released
T-Ruby v0.0.42 adds full Ruby 4.0 support, released just days after Ruby 4.0's Christmas release. (PR#28)
T-Ruby v0.0.42 adds full Ruby 4.0 support, released just days after Ruby 4.0's Christmas release. (PR#28)
T-Ruby v0.0.41 introduces keyword arguments syntax, bringing more expressive type annotations to your Ruby code. (PR#27)
T-Ruby v0.0.40 brings significant parser improvements, including access modifier support and heredoc detection. (PR#22)
We're excited to introduce T-Ruby, a TypeScript-style static type system for Ruby.
T-Ruby brings the familiar TypeScript development experience to Ruby developers, allowing you to add type annotations directly in your code and catch type errors before runtime.
.rbs signature filesInstall T-Ruby and start adding types to your Ruby code:
gem install t-ruby
Create your first .trb file:
def greet(name: String): String
"Hello, #{name}!"
end
Compile to Ruby:
trc greet.trb
Check out our documentation to learn more!
T-Ruby now automatically infers return types from your code. No more explicit annotations for obvious types!
Previously, you had to write:
def greet(name: String): String
"Hello, #{name}!"
end
Now, the return type is optional:
def greet(name: String)
"Hello, #{name}!"
end
T-Ruby infers that greet returns String and generates the correct RBS:
def greet: (name: String) -> String
The new type inference engine analyzes method bodies to determine return types:
"hello" → String, 42 → Integerstr.upcase → Stringif/else branchesclass Calculator
def double(n: Integer)
n * 2
end
def is_positive?(n: Integer)
n > 0
end
end
Generated RBS:
class Calculator
def double: (n: Integer) -> Integer
def is_positive?: (n: Integer) -> bool
end
class User
def initialize(name: String)
@name = name
end
def greeting
"Hello, #{@name}!"
end
end
Generated RBS:
class User
@name: String
def initialize: (name: String) -> void
def greeting: () -> String
end
The inference system is inspired by TypeScript's approach:
For a deep dive into the implementation, check out our technical blog post.
Update to the latest T-Ruby and enjoy automatic type inference:
gem update t-ruby
Your existing code will work as before - explicit types still take precedence. The inference only kicks in when return types are omitted.
We'd love to hear your experience with type inference. Found an edge case? Have suggestions? Open an issue on GitHub.
Happy typing!