Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the generics of the struct based on the type of its attributes #179

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

rhiroe
Copy link
Contributor

@rhiroe rhiroe commented Jan 10, 2025

Account = Struct.new(
  :id,    #: Integer
  :email, #: String
)

This Ruby code generates the following RBS code:

class Account < Struct[Integer | String]
  attr_accessor id(): Integer

  attr_accessor email(): String

  def self.new: (?Integer id, ?String email) -> instance
              | (?id: Integer, ?email: String) -> instance
end

@rhiroe rhiroe marked this pull request as ready for review January 10, 2025 09:12
```rb
Account = Struct.new(
  :id,    #: Integer
  :email, #: String
)
```
This Ruby code generates the following RBS code:
```rbs
class Account < Struct[Integer | String]
  attr_accessor id(): Integer

  attr_accessor email(): String

  def self.new: (?Integer id, ?String email) -> instance
             | (?id: Integer, ?email: String) -> instance
end
```
Copy link
Owner

@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 enabled auto-merge January 23, 2025 08:05
@soutaro soutaro merged commit fbe975c into soutaro:main Jan 23, 2025
4 checks passed
@rhiroe rhiroe deleted the patch-hiroe-2 branch January 23, 2025 08:55
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