Skip to content
instance method

StringScanner#unscan

() -> void
unscan → self

Sets the position to its value previous to the recent successful match attempt:

Example
scanner = StringScanner.new('foobarbaz')
scanner.scan(/foo/)
put_situation(scanner)
# Situation:
#   pos:       3
#   charpos:   3
#   rest:      "barbaz"
#   rest_size: 6
scanner.unscan
# => #<StringScanner 0/9 @ "fooba...">
put_situation(scanner)
# Situation:
#   pos:       0
#   charpos:   0
#   rest:      "foobarbaz"
#   rest_size: 9

Raises an exception if match values are clear:

Example
scanner.scan(/nope/)           # => nil
match_values_cleared?(scanner) # => true
scanner.unscan                 # Raises StringScanner::Error.
See also #terminate #values_at #string= also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0