diff --git a/stdlib/strscan/0/string_scanner.rbs b/stdlib/strscan/0/string_scanner.rbs index e0419e148..42accd220 100644 --- a/stdlib/strscan/0/string_scanner.rbs +++ b/stdlib/strscan/0/string_scanner.rbs @@ -498,7 +498,7 @@ class StringScanner # scanner[0] # => nil # scanner[1] # => nil # - def []: (Integer) -> String? + def []: (Integer | String | Symbol) -> String? # + # Returns the array of captured match values at indexes (1..) + # if the most recent match attempt succeeded, or nil otherwise; + # see [Captured Match Values](rdoc-ref:StringScanner@Captured+Match+Values): + # scanner = StringScanner.new('Fri Dec 12 1975 14:39') + # scanner.named_captures # => {} + # + # pattern = /(?\w+) (?\w+) (?\d+) / + # scanner.match?(pattern) + # scanner.named_captures # => {"wday"=>"Fri", "month"=>"Dec", "day"=>"12"} + # + # scanner.string = 'nope' + # scanner.match?(pattern) + # scanner.named_captures # => {"wday"=>nil, "month"=>nil, "day"=>nil} + # + # scanner.match?(/nosuch/) + # scanner.named_captures # => {} + # + def named_captures: () -> Hash[String, String?] + # + # Peeks at the current byte and returns it as an integer. + # + # s = StringScanner.new('ab') + # s.peek_byte # => 97 + # + def peek_byte: () -> Integer? + # # call-seq: # pos -> byte_position @@ -1092,7 +1126,7 @@ class StringScanner # scanner.match?(/nope/) # => nil # scanner.post_match # => nil # - def post_match: () -> String + def post_match: () -> String? # + # Scans one byte and returns it as an integer. This method is not multibyte + # character sensitive. See also: #getch. + # + def scan_byte: () -> Integer? # + # If `base` isn't provided or is `10`, then it is equivalent to calling + # #scan with a `[+-]?d+` pattern, and returns an Integer or nil. + # + # If `base` is `16`, then it is equivalent to calling #scan with a + # `[+-]?(0x)?[0-9a-fA-F]+` pattern, and returns an Integer or nil. + # + # The scanned string must be encoded with an ASCII compatible encoding, + # otherwise Encoding::CompatibilityError will be raised. + # + def scan_integer: (?base: Integer) -> Integer? #