Skip to content

Commit d4d60ac

Browse files
committed
Update inline.md for the parameter syntax
1 parent 3e7c184 commit d4d60ac

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

docs/inline.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,60 @@ end
219219

220220
#### Doc-style syntax
221221

222+
The doc-style syntax allows annotating individual method parameters and the return type using `@rbs NAME: TYPE` comments.
223+
224+
The `@rbs PARAM_NAME: T` syntax declares the type of a parameter:
225+
226+
```ruby
227+
class Calculator
228+
# @rbs x: Integer
229+
# @rbs y: Integer
230+
def add(x, y:)
231+
x + y
232+
end
233+
end
234+
```
235+
236+
You can add a description after `--`:
237+
238+
```ruby
239+
class Calculator
240+
# @rbs x: Integer -- the first operand
241+
# @rbs y: Integer -- the second operand
242+
def add(x, y:)
243+
x + y
244+
end
245+
end
246+
```
247+
222248
The `@rbs return: T` syntax declares the return type of a method:
223249

224250
```ruby
225251
class Calculator
226-
# @rbs return: String
252+
# @rbs return: String -- a human-readable representation
227253
def to_s
228254
"Calculator"
229255
end
230256
end
231257
```
232258

259+
Both can be combined:
260+
261+
```ruby
262+
class Calculator
263+
# @rbs x: Integer -- the first operand
264+
# @rbs y: Integer -- the second operand
265+
# @rbs return: Integer
266+
def add(x, y:)
267+
x + y
268+
end
269+
end
270+
```
271+
233272
### Current Limitations
234273

235274
- Class methods and singleton methods are not supported
236-
- Parameter types are not supported with doc-style syntax
275+
- Only positional and keyword parameters are supported. Splat parameters (`*x`, `**y`) and block parameter (`&block`) are not supported yet.
237276
- Method visibility declaration is not supported yet
238277

239278
## Attributes

0 commit comments

Comments
 (0)