Re:T-Ruby is Ruby with syntax for types
by jrochkind1 on Friday December 26, 2025 @09:19PM
(#46398481)
Wait, what happens if you want keyword arguments?
[ Parent
| on HN ]
Yeah, it doesn't work with keyword arguments. In the playground I tried a simple keyword with default value, and it converted to the wrong thing, as if "someone" was a valid type.
def greet(name: "someone"): String
"Hello, #{name}!"
end
Re:T-Ruby is Ruby with syntax for types
by t-writescode on Friday December 26, 2025 @10:25PM
(#46398799)
keyword arguments are, internally, syntactic sugar over a hash. It probably doesn't easily work with typing the explicit values of a raw hash
Re:T-Ruby is Ruby with syntax for types
by anamexis on Saturday December 27, 2025 @01:29AM
(#46399638)
This hasn’t been true since Ruby 3.0. Keyword arguments are a core language feature with their own semantics.
Re:T-Ruby is Ruby with syntax for types
by t-writescode on Saturday December 27, 2025 @03:54AM
(#46400287)
Oh huh, TIL. Thanks for sharing!
The obvious thing that comes to mind when looking at their spotlight example.
However, no mention of this basic head scratcher in the docs. :rolling_eyes:
Re:T-Ruby is Ruby with syntax for types
by anamexis on Saturday December 27, 2025 @01:26AM
(#46399630)
It would seem that in T-Ruby all arguments are keyword arguments, although they don’t really spell this out.
https://type-ruby.github.io/docs/learn/functions/optional-re...
Their docs say that something like:
`def greet(name: String, greeting: String = "Hello"): String`
will work for kwargs with default values — https://type-ruby.github.io/docs/getting-started/understandi...
I think they've missed a trick there, they could have used `|` like low-type does.
e.g.
def greet(name: String | "Hello"): String
I know it's all subjective but I think that reads better and it's valid ruby.To be honest low-type with a static analysis tool would be my favourite syntax for this.
Re:T-Ruby is Ruby with syntax for types
by jrochkind1 on Saturday December 27, 2025 @07:11AM
(#46401289)
That example is for positional args with default values, according to the example usage: `greet("Alice")`. Can't find ruby-style keyword args example, with or without default values. maybe no kw args in t-ruby?
Or wait, found examples that claims to be keyword arguments, but you define them just the same? I'm confused. https://type-ruby.github.io/docs/learn/functions/optional-re...