Proposal: allow to specify Union type for the module-self
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 256
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 37
Description
It would be very helpful to use Union type for the module-self.
In my project, I have a Commentable concern module used across multiple ActiveRecord models. This Commentable module uses methods commonly defined in the modules where it is included. For example, it references methods like #comments and attributes such as #user_id.
Currently, in RBS, only classes or interfaces can be specified for module-self. As a workaround, I have defined an interface as follows:
interface _Commentable
def comments: () -> Comment::ActiveRecord_Relation
def user_id: () -> Integer
...
end
module Commentable : _Commentable
end
This interface allows for proper type checking, but as the number of methods grows, the interface definition becomes more cumbersome.
If it were possible to specify a Union type for module-self, it would allow for type definitions of modules without the need to define an interface.
module Commentable : (Article | Comment | ...)
end
However, generating an interface dynamically through Union types might negatively impact runtime performance. Do you think this idea is practical?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing _Commentable interface workaround and the proposed module-self Union syntax in this issue. Review how RBS represents module-self and Union types, then assess the type-checking and runtime-performance implications raised here. Done means an accepted design with implementation and tests, if the proposal is approved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100