Skip to content

Commit

Permalink
Merge pull request #1625 from Forthoney/patch-1
Browse files Browse the repository at this point in the history
Add description about rbs prototype
  • Loading branch information
soutaro authored Nov 20, 2023
2 parents 47a57ff + 3d9f800 commit 81c601e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,53 @@ $ rbs methods ::Object
$ rbs method Object then
```

An end user of `rbs` will probably find `rbs prototype` the most useful. This command generates boilerplate signature declarations for ruby files. For example, say you have written the below ruby script.

```ruby
# person.rb
class Person
attr_reader :name
attr_reader :contacts

def initialize(name:)
@name = name
@contacts = []
end

def speak
"I'm #{@name} and I love Ruby!"
end
end
```

Running prototype on the above will automatically generate

```
$ rbs prototype rb person.rb
class Person
@name: untyped
@contacts: untyped
attr_reader name: untyped
attr_reader contacts: untyped
def initialize: (name: untyped) -> void
def speak: () -> ::String
end
```

It prints signatures for all methods, classes, instance variables, and constants.
This is only a starting point, and you should edit the output to match your signature more accurately.

`rbs prototpe` offers three options.

- `rb` generates from just the available Ruby code
- `rbi` generates from Sorbet RBI
- `runtime` generates from runtime API

## Library

There are two important concepts, _environment_ and _definition_.
Expand Down

0 comments on commit 81c601e

Please sign in to comment.