expect.rb

来自「ruby的源代码」· RB 代码 · 共 37 行

RB
37
字号
$expect_verbose = falseclass IO  def expect(pat,timeout=9999999)    buf = ''    case pat    when String      e_pat = Regexp.new(Regexp.quote(pat))    when Regexp      e_pat = pat    end    while true      if IO.select([self],nil,nil,timeout).nil? then        result = nil        break      end      c = getc.chr      buf << c      if $expect_verbose        STDOUT.print c        STDOUT.flush      end      if mat=e_pat.match(buf) then        result = [buf,*mat.to_a[1..-1]]        break      end    end    if iterator? then      yield result    else      return result    end    nil  endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?