Re: getting the next line with the iterator

do. I want to be able to access the next iterator while
reading a file.
Basically, I want to be able to collect the next 3 lines when I
encounter a certain line:

I find this the most readable way to do it, though using generator is
probably slower than just keeping track of the last 3 lines as you go

require ‘generator’
list = []‘toto.txt’, ‘rb’) do |myFile|
g =
if =~ /regExp/
3.times { list << }
puts list

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs