Skip to content

Commit

Permalink
Add Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenprater committed Jan 10, 2025
1 parent 3414968 commit dd37149
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions manual/compiler_delegate.md
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


1 change: 1 addition & 0 deletions manual/compilers.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ In the following section you will find all available DSL compilers:
* [JsonApiClientResource](compiler_jsonapiclientresource.md)
* [Kredis](compiler_kredis.md)
* [MixedInClassAttributes](compiler_mixedinclassattributes.md)
* [Module#delegate (ActiveSupport)](compiler_delegate.md)
* [Protobuf](compiler_protobuf.md)
* [RailsGenerators](compiler_railsgenerators.md)
* [SidekiqWorker](compiler_sidekiqworker.md)
Expand Down

0 comments on commit dd37149

Please sign in to comment.