如何打印包含制表符的Ruby文件中的行?

如何打印包含制表符的Ruby文件中的行?,ruby,Ruby,我有两个文件,test1.rb和test2.rb。test1.rb在第82行和第84行包含制表符 我想要这样的打印件: test1.rb: 82 (it means that there are TAB included in the line of 82). test1.rb: 84 (it means that there are TAB included in the line of 84). 我会这样做: ["test1.rb", "test2.rb"].each do |fn|

我有两个文件,test1.rb和test2.rb。test1.rb在第82行和第84行包含制表符

我想要这样的打印件:

test1.rb: 82 (it means that there are TAB included in the line of 82).
test1.rb: 84 (it means that there are TAB included in the line of 84).
我会这样做:

["test1.rb", "test2.rb"].each do |fn|
  File.foreach(fn) do |li|
    puts "#{ fn }: #{ $. }" if li["\t"]
  end
end
美元。表示正在读取的文件中的当前行号。

我会这样做:

["test1.rb", "test2.rb"].each do |fn|
  File.foreach(fn) do |li|
    puts "#{ fn }: #{ $. }" if li["\t"]
  end
end
美元。表示正在读取的文件中的当前行号