File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments