我在迭代文件的行时遇到一些问题,似乎每个文件只能使用一次each_line方法
file = open_file(path)
file.each_line { puts "Q"}
puts "--"
file.each_line { puts "Q"}
puts "--"
file.each_line { puts "Q"}
puts "--"
file.each_line { puts "Q"}
#Output: (on a file with three lines in it )
#Q
#Q
#Q
#--
#--
#--
Run Code Online (Sandbox Code Playgroud)
它与常规迭代器一起工作正常
3.times { puts "Q"}
puts "--"
3.times { puts "Q"}
puts "--"
3.times { puts "Q"}
puts "--"
3.times { puts "Q"}
#Output: (on a file with three lines in it )
#Q
#Q
#Q
#--
#Q …Run Code Online (Sandbox Code Playgroud)