-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3414968
commit dd37149
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Module#delegate | ||
|
||
`Tapioca::Dsl::Compilers::Delegate` generates RBI files for classes that use the `delegate` method | ||
from ActiveSupport. | ||
|
||
For a class like: | ||
|
||
```ruby | ||
class Delegator | ||
sig { returns(Target) } | ||
attr_reader :target | ||
|
||
delegate :method, to: :target | ||
end | ||
|
||
class Target | ||
sig { returns(String) } | ||
def method = "hi" | ||
end | ||
``` | ||
|
||
This compiler will generate the following RBI file: | ||
|
||
```rbi | ||
class Delegator | ||
sig { returns(Target) } | ||
attr_reader :target | ||
|
||
sig { returns(String) } | ||
def method; end | ||
end | ||
``` | ||
|
||
The `delegate` method can also take the `prefix`, `private` and `allow_nil` | ||
options but is not intelligent about discovering types from instance variables, | ||
class variables or constants other than classes - if you delegate to a target | ||
whose type is not discoverable statically, the type will default to T.untyped | ||
|
||
Delegates that _themselves_ return a `T.untyped` value will not be generated in | ||
the RBI file, since Sorbet already generates a `T.untyped` return by default | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters