このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 3.2 リファレンスマニュアル

instance method StringScanner#clear

terminate -> self[permalink][rdoc][edit]
clear -> self

スキャンポインタを文字列末尾後まで進め、マッチ記録を捨てます。

[RETURN]
self を返します。

pos = self.string.size と同じ動作です。

require 'strscan'

s = StringScanner.new('test string')
p s.scan(/\w+/) # => "test"
p s.matched   # => "test"
p s.pos       # => 4
p s[0]        # => "test"
s.terminate
p s.matched   # => nil
p s[0]        # => nil
p s.pos       # => 11

StringScanner#clear は将来のバージョンで削除される予定です。代わりに StringScanner#terminate を使ってください。