You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: strscan.rb
    path of file: ./repos/natalie/lib
    
    the code of the file until where you have to start completion: class StringScanner
  class Error < StandardError
  end

  private def initialize(string)
    @string = string.to_str
    @pos = 0
    @prev_pos = nil
    @matched = nil
  end

  attr_reader :string, :matched, :pos

  def inspect
    if @pos >= @string.size
      '#<StringScanner fin>'
    else
      before
    
  def exist?(pattern)
    raise TypeError, "wrong argument type #{pattern.class.name} (expected Regexp)" unless pattern.is_a?(Regexp)
    return 0 if pattern == //
    start = @pos
    loop do
      if check(pattern)
        found_at = @pos - start + 1
        @pos = start
        return found_at
      end
      if @pos >= @string.size
        @pos = start
        return nil
      end