Skip to content

Commit 382c051

Browse files
committed
Add Mixin section
1 parent 4ac2cef commit 382c051

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docs/inline.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,80 @@ The attribute definitions are ignored because the names are given by string lite
266266
### Current Limitations
267267
268268
- Attribute visibility is not supported yet. All attributes are _public_
269+
270+
## Mixin
271+
272+
Inline RBS supports Ruby's mixin methods: `include`, `extend`, and `prepend`.
273+
274+
```ruby
275+
module Printable
276+
# @rbs () -> String
277+
def to_print
278+
to_s
279+
end
280+
end
281+
282+
class Document
283+
include Printable
284+
extend Enumerable #[String]
285+
prepend Trackable
286+
end
287+
```
288+
289+
It detects these mixin declarations and adds them to the class or module definition.
290+
291+
### Basic mixin usage
292+
293+
Mixins work just like in regular RBS files:
294+
295+
```ruby
296+
module Helper
297+
end
298+
299+
class MyClass
300+
include Helper
301+
extend Helper
302+
prepend Helper
303+
end
304+
```
305+
306+
### Type arguments for generic modules
307+
308+
You can specify type arguments for generic modules using the `#[...]` syntax:
309+
310+
```ruby
311+
class TodoList
312+
include Enumerable #[String]
313+
314+
# @rbs () { (String) -> void } -> void
315+
def each(&block)
316+
@items.each(&block)
317+
end
318+
end
319+
```
320+
321+
### Module name requirements
322+
323+
Only constant module names are supported. Dynamic module references are not allowed:
324+
325+
```ruby
326+
class MyClass
327+
include Helper # ✓ Works - constant name
328+
329+
mod = Helper
330+
include mod # ✗ Ignored - non-constant module reference
331+
332+
include Helper.new # ✗ Ignored - not a simple constant
333+
end
334+
```
335+
336+
### Module name resolution
337+
338+
The module name resolution is based on the nesting of the class/module definitions, unlike Ruby.
339+
340+
Modules accessible through ancestors (super-class/included modules) are not supported.
341+
342+
### Current Limitations
343+
344+
- Only single module arguments are supported (no `include A, B` syntax)
345+
- Module names must be constants

0 commit comments

Comments
 (0)