ruby / ruby/rbs

Using `singleton` on variables

Open
#558 1 comment 2 reactions 0 assignees View on GitHub

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 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test path is named. Start by locating RBS's existing handling for singleton types and type variables, using the EventBus signature as the reproducer. Done means singleton can express the type variable from the to: argument and the subscriber/event relationship is covered by tests.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.