Skip to content

Commit

Permalink
Merge pull request #1617 from ksss/struct-data-runtime-doc
Browse files Browse the repository at this point in the history
Add doc for Generating RBS
  • Loading branch information
soutaro authored Nov 22, 2023
2 parents 73a6a02 + 2d7953b commit a737401
Showing 1 changed file with 29 additions and 0 deletions.
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
```

0 comments on commit a737401

Please sign in to comment.