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

Add doc for Generating RBS #1617

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/data_and_struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,32 @@ Measure.ancestors #=> [Measure, #<Class:0xOOF>, Data, ...]
```

[^1]: [Shannon Skipper](https://github.com/havenwood) told me it in Discord

## Generate prototype for `Data` and `Struct`

RBS prototypes for classes using `Data` and `Struct` can be generated by `rbs prototype runtime`.

```rb
# t.rb
class Measure < Data.define(:amount, :unit)
end
```

```
$ bundle exec rbs prototype runtime -R t.rb Measure
class Measure < ::Data
def self.new: (untyped amount, untyped unit) -> instance
| (amount: untyped, unit: untyped) -> instance

def self.[]: (untyped amount, untyped unit) -> instance
| (amount: untyped, unit: untyped) -> instance

def self.members: () -> [ :amount, :unit ]

def members: () -> [ :amount, :unit ]

attr_reader amount: untyped

attr_reader unit: untyped
end
```