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

Handling Classes created with Data#define #1563

Open
Forthoney opened this issue Oct 12, 2023 · 1 comment
Open

Handling Classes created with Data#define #1563

Forthoney opened this issue Oct 12, 2023 · 1 comment

Comments

@Forthoney
Copy link
Contributor

The dynamic nature of defining Data classes with Data#define makes it difficult (if not impossible) to adequately describe scripts using RBS.
If it indeed is impossible, perhaps we should consider a specific syntax for Data classes in RBS. Yes, they are dynamically created classes, so checking is tough, but it is odd to have a first class, core library feature not supported by RBS.
If it is possible and I simply did not know, perhaps updating the tutorial to better discuss how to do this would be very helpful

@ksss
Copy link
Collaborator

ksss commented Oct 12, 2023

I have an idea. How about generating prototype RBS when rbs prototype runtime detects Struct and Data? (It's not implemented yet.)
Would this be of help to you?

For example:

# foo.rb
class Foo < Data.define(:foo, :bar)
end

$ rbs prototype runtime -R foo.rb Foo

# foo.rbs
class Foo < Data
  def initialize: (untyped foo, untyped bar) -> void
                | (foo: untyped, bar: untyped) -> void
  attr_reader foo: untyped
  attr_reader bar: untyped
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants