Skip to content

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

instance method

StringScanner#peek

peek(len)

Extracts a string corresponding to string[pos,len], without advancing the scan pointer.

Example
s = StringScanner.new('test string')
s.peek(7)          # => "test st"
s.peek(7)          # => "test st"
See also #matched_size #peep #matched? #pointer also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0