ruby / ruby/rbs

[Proposal] Make`-> void` return type annotation on `initialize` methods to be implicit

Open
#2,634 1 comment 3 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

I propose simplifying the RBS syntax for initialize methods by removing the required -> void return type annotation.

Current Syntax:

#: (a: String) -> void
def initialize(a:)
  @a = a
end

Proposed Syntax:

#: (a: String?)
def initialize(a:)
  @a = a
end

Why?

  1. Redundant - I was moving from Sorbet sigs to RBS style sigs and noticed that I was adding the -> void to every initialize method. Even though it makes sense from a completeness perspective, it seemed redundant to me and does not add any new information.

  2. Initialize is special - The initialize method is already special in Ruby - it's the only method that is called indirectly through new, cannot meaningfully return a value to its caller, has a fixed, unchangeable return behavior. Making its type signature special in RBS would accurately reflect its special status in the language.

  3. Comparison with other languages:

    Language Example Requires Return Type?
    Python (with types) def __init__(self, a: str): Optional
    TypeScript constructor(a: string) { } No
    Java public MyClass(String a) { } No
    C# public MyClass(string a) { } No
    Go N/A - uses factory functions instead N/A
    Ruby (current RBS) #: (a: String) -> void Yes

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

The issue names no files or tests. Start by locating the RBS parser and validation paths for initialize method signatures, then compare the current and proposed syntax examples. Done requires an agreed design for the special return-type rule, with its behavior documented and covered by appropriate 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
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.