Skip to content

Conversation

@Morriar
Copy link
Contributor

@Morriar Morriar commented May 6, 2025

With Sorbet we use RBS signatures directly as comments:

#: (Integer, Integer) -> Integer
def add(a, b)
  a + b
end

We parse these comments using rbs_parse_method_type.

When it comes to generic class we want to offer the same syntax so the user can simply specify the type parameters:

#: [in A, B < Object]
class Foo
end

We need to expose a parsing method for those.

Note that the Ruby method is not required per se, it just makes it easier to test.

Morriar added 4 commits May 6, 2025 11:07
This is useful to parse a "class signature" such as this:

```rb
\#: [in A, B = String, out < Object]
class Foo; end
```

Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@soutaro soutaro added this to the RBS 4.0 milestone May 9, 2025
@soutaro soutaro added this pull request to the merge queue May 9, 2025
Merged via the queue into ruby:master with commit beddc99 May 9, 2025
20 checks passed
soutaro added a commit that referenced this pull request Oct 10, 2025
Expose a method to parse type parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants