Skip to content

Commit de00641

Browse files
committed
Update inline.md
1 parent 6833200 commit de00641

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/inline.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,31 @@ Modules accessible through ancestors (super-class/included modules) are not supp
360360

361361
- Only single module arguments are supported (no `include A, B` syntax)
362362
- Module names must be constants
363+
364+
## Instance Variables
365+
366+
Inline RBS declaration allows defining instance variables.
367+
368+
```ruby
369+
class Person
370+
# @rbs @name: String
371+
# @rbs @age: Integer? --
372+
# how old is the person?
373+
# `nil` means it's unspecified.
374+
375+
# @rbs (String name, Integer? age) -> void
376+
def initialize(name, age)
377+
@name = name
378+
@age = age
379+
end
380+
end
381+
```
382+
383+
The `@rbs @VAR-NAME: TYPE` syntax enclosed in `class`/`module` syntax declares instance variables.
384+
You can add the documentation of the variable followed by two hyphones (`--`).
385+
386+
Instance variable declarations must be under the `class`/`module` syntax, and they are ignored if written inside method definitions.
387+
388+
### Current Limitations
389+
390+
- Only instance variables of class/module instances are allowed

0 commit comments

Comments
 (0)