Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

StringScanner#unscan

unscan

Sets the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.

Example
s = StringScanner.new('test string')
s.scan(/\w+/)        # => "test"
s.unscan
s.scan(/../)         # => "te"
s.scan(/\d/)         # => nil
s.unscan             # ScanError: unscan failed: previous match record not exist
See also #terminate #values_at #string= also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1