替换QQ号码的ruby代码

我土鳖了。。。 英语: 问号应该是 question mark .
从 temp.txt 读入,写结果到 result.txt


def test_substitute_qq_number_with_wenhao_in_a_file
file = "temp.txt"
TextFormatter.substitute_qq_number_with_wenhao_in_a_file(file)
end

def test_substitute_qq_number_with_wenhao
result = TextFormatter.substitute_qq_number_with_wenhao("510045240")
assert result == "5100452??"
result = TextFormatter.substitute_qq_number_with_wenhao("123456789012")
assert result == "1234567890??"
result = TextFormatter.substitute_qq_number_with_wenhao("12345")
assert result == "123??"
end



def TextFormatter.substitute_qq_number_with_wenhao_in_a_file(file)
qq_number_regexp=Regexp.new('\d{5,12}')
File.open(file) do |file|
while line=file.gets

if !line.index(qq_number_regexp)
@@text <<line
else
@@text << TextFormatter.substitute_qq_number_with_wenhao(line)
end
end
end
TextFormatter.write_to_file("result.txt", @@text) 

end