Skip to content

Commit 6ce7767

Browse files
ksssclaude
andcommitted
Update docs/inline.md to match current inline parser behavior
- Remove outdated method limitations (singleton methods, splat/block params) - Add note that singleton methods (`def self.NAME`) are supported - Document trailing `#:` annotation for method return types - Fix constant type inference: Symbol literals infer to `Symbol`, not the singleton symbol type; add `nil` to the list - Add Skip Annotation section for `@rbs skip` - Add limitations: `class << self`, top-level def, non-self receiver, top-level attr_* - Fix typos: "hyphones" -> "hyphens", "infered" -> "inferred" Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 01afaa8 commit 6ce7767

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

docs/inline.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Inline RBS supports methods defined using the `def` syntax in Ruby.
163163
```ruby
164164
class Calculator
165165
def add(x, y) = x+y
166+
167+
def self.zero = 0
166168
end
167169
```
168170
@@ -233,6 +235,18 @@ The type of both methods is `(Integer, Integer) -> Integer | (Float, Float) -> F
233235
> The `@rbs METHOD-TYPE` syntax allows overloads with the `|` operator, just like in RBS files.
234236
> Multiple `: METHOD-TYPE` declarations are required for overloads.
235237

238+
The `#:` syntax can also be used as a trailing annotation to declare the return type of a method:
239+
240+
```ruby
241+
class Calculator
242+
def add(x, y) #: Integer
243+
x + y
244+
end
245+
246+
def subtract(x, y) = x - y #: Integer
247+
end
248+
```
249+
236250
The `@rbs METHOD-TYPE` syntax allows having `...` at the last part.
237251

238252
```ruby
@@ -337,9 +351,10 @@ end
337351
338352
### Current Limitations
339353
340-
- Class methods and singleton methods are not supported
341-
- Only positional and keyword parameters are supported. Splat parameters (`*x`, `**y`) and block parameter (`&block`) are not supported yet.
342354
- Method visibility declaration is not supported yet
355+
- The `class << self` syntax is not supported
356+
- Top-level method definitions (outside any class/module) are not supported
357+
- Method definitions with a non-self receiver (e.g. `def obj.foo`) are not supported
343358
344359
## Attributes
345360
@@ -417,6 +432,7 @@ The attribute definitions are ignored because the names are given by string lite
417432
### Current Limitations
418433

419434
- Attribute visibility is not supported yet. All attributes are _public_
435+
- Top-level attribute definitions (outside any class/module) are not supported
420436

421437
## Mixin
422438

@@ -515,7 +531,7 @@ end
515531
```
516532
517533
The `@rbs @VAR-NAME: TYPE` syntax enclosed in `class`/`module` syntax declares instance variables.
518-
You can add the documentation of the variable followed by two hyphones (`--`).
534+
You can add the documentation of the variable followed by two hyphens (`--`).
519535
520536
Instance variable declarations must be under the `class`/`module` syntax, and they are ignored if written inside method definitions.
521537
@@ -547,14 +563,16 @@ The types of constants may be automatically inferred when the right-hand side co
547563
- **Floats**: `RATE = 3.14``Float`
548564
- **Booleans**: `ENABLED = true``bool`
549565
- **Strings**: `NAME = "test"``String`
550-
- **Symbols**: `STATUS = :ready``:ready`
566+
- **Symbols**: `STATUS = :ready``Symbol`
567+
- **Nil**: `EMPTY = nil``nil`
551568
552569
```ruby
553570
MAX_SIZE = 100 # Inferred as Integer
554571
PI = 3.14159 # Inferred as Float
555572
DEBUG = false # Inferred as bool
556573
APP_NAME = "MyApp" # Inferred as String
557-
DEFAULT_MODE = :strict # Inferred as :strict
574+
DEFAULT_MODE = :strict # Inferred as Symbol
575+
NONE = nil # Inferred as nil
558576
```
559577
560578
### Explicit Type Annotations
@@ -595,10 +613,22 @@ MyKernel = Kernel #: module-alias
595613
596614
This creates new type names that refer to the same class or module as the original.
597615
598-
The annotations can have optional type name to specify the class/module name, for the case it cannot be infered through the right-hand-side of the constant declaration.
616+
The annotations can have optional type name to specify the class/module name, for the case it cannot be inferred through the right-hand-side of the constant declaration.
599617
600618
```ruby
601619
MyObject = object #: class-alias Object
602620
603621
MyKernel = kernel #: module-alias Kernel
604622
```
623+
624+
## Skip Annotation
625+
626+
The `@rbs skip` annotation makes inline RBS ignore the following declaration.
627+
628+
```ruby
629+
class Calculator
630+
# @rbs skip
631+
def debug_internal
632+
end
633+
end
634+
```

0 commit comments

Comments
 (0)