rbs
rbs copied to clipboard
Using `singleton` on variables
It would be useful to be able to apply singleton to type variables as well as concrete types. As a motivating example consider this simple event bus:
interface _Subscriber[E]
def call: (E event) -> void
end
class EventBus
def subscribe: [E] (_Subscriber[E] subscriber, to: singleton(E)) -> void
def dispatch: (untyped event) -> void
end
Here I want to specify that EventBus#subscribe expects the subscriber to handle events of the type given as the to: argument.
I faced such problem too
For example, in my case I would like to do smth like:
class Builder
def self.build: [C] (singleton(C) class) -> Array[C]
end