ruby正则表达式打印匹配行

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

class Filetest
	attr_accessor :filename

	def initialize(filename)
		@filename = filename
	end

	def puts_file_line(word)
		File.open(@filename, "r") do |file|
			while line = file.gets
				if line =~ /#{word}/
					p line.chomp
				end
			end
		end
	end

end

file = Filetest.new("test")

file.puts_file_line("hello")