From 43f5a82c788e9020c5895c957a56e89dcdba87ec Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 15 May 2026 20:13:52 +0100 Subject: [PATCH 1/2] [DOC] Doc for StringScanner#scan_integer --- lib/strscan/strscan.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/strscan/strscan.rb b/lib/strscan/strscan.rb index 46acc7ea82..15f2e12a3d 100644 --- a/lib/strscan/strscan.rb +++ b/lib/strscan/strscan.rb @@ -2,16 +2,34 @@ class StringScanner # call-seq: - # scan_integer(base: 10) + # scan_integer(base: 10) -> integer or nil # - # 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. + # Returns an integer scanned from +self+, + # beginning at the current position; + # returns +nil+ if no such integer was available. # - # 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. + # When `base` is `10` (the default), + # equivalent to calling #scan with argument +pattern+ + # as '[+-]?\d+': # - # The scanned string must be encoded with an ASCII compatible encoding, otherwise - # Encoding::CompatibilityError will be raised. + # scanner = StringScanner.new('Form 27B/6') + # scanner.scan_integer # => nil # No integer at position 0. + # scanner.pos = 5 + # scanner.scan_integer # => 27 + # scanner.matched # => "27" + # scanner.pos # => 7 + # + # When `base` is `16` (the only other value allowed), + # equivalent to calling #scan with argument +pattern+ + # as '[+-]?(0x)?[0-9a-fA-F]+': + # + # scanner.pos = 5 + # scanner.scan_integer(base: 16) # => 635 + # scanner.matched # => "27B" + # scanner.pos # => 8 + # + # Raises Encoding::CompatibilityError if +self+ does not have + # an ASCII compatible encoding. def scan_integer(base: 10) case base when 10 From 9fb2d71df375ee419c877faf818476bf009f92fb Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 18 May 2026 15:05:22 +0100 Subject: [PATCH 2/2] Change to markdown format --- lib/strscan/strscan.rb | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/strscan/strscan.rb b/lib/strscan/strscan.rb index 15f2e12a3d..07ed102d9a 100644 --- a/lib/strscan/strscan.rb +++ b/lib/strscan/strscan.rb @@ -1,34 +1,40 @@ # frozen_string_literal: true class StringScanner + # :markup: markdown + # # call-seq: # scan_integer(base: 10) -> integer or nil # - # Returns an integer scanned from +self+, + # Returns an integer scanned from `self`, # beginning at the current position; - # returns +nil+ if no such integer was available. + # returns `nil` if no such integer was available. # # When `base` is `10` (the default), # equivalent to calling #scan with argument +pattern+ - # as '[+-]?\d+': + # as `'[+-]?\d+'`: # - # scanner = StringScanner.new('Form 27B/6') - # scanner.scan_integer # => nil # No integer at position 0. - # scanner.pos = 5 - # scanner.scan_integer # => 27 - # scanner.matched # => "27" - # scanner.pos # => 7 + # ```ruby + # scanner = StringScanner.new('Form 27B/6') + # scanner.scan_integer # => nil # No integer at position 0. + # scanner.pos = 5 + # scanner.scan_integer # => 27 + # scanner.matched # => "27" + # scanner.pos # => 7 + # ``` # # When `base` is `16` (the only other value allowed), - # equivalent to calling #scan with argument +pattern+ - # as '[+-]?(0x)?[0-9a-fA-F]+': + # equivalent to calling #scan with argument `pattern` + # as `'[+-]?(0x)?[0-9a-fA-F]+'`: # - # scanner.pos = 5 - # scanner.scan_integer(base: 16) # => 635 - # scanner.matched # => "27B" - # scanner.pos # => 8 + # ```ruby + # scanner.pos = 5 + # scanner.scan_integer(base: 16) # => 635 + # scanner.matched # => "27B" + # scanner.pos # => 8 + # ``` # - # Raises Encoding::CompatibilityError if +self+ does not have + # Raises Encoding::CompatibilityError if `self` does not have # an ASCII compatible encoding. def scan_integer(base: 10) case base