From: Bill Guindon Date: 2006-04-28T08:03:31+09:00 Subject: Re: getting the next line with the iterator On 4/27/06, Eric Boucher wrote: > Hi, > > I would like to know if there is a ruby way to achieve what I want to > 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: > Something like this maybe? list = [] matched = -1 File.open('ruby.txt', 'rb') do |myFile| myFile.each {|line| matched = 0 if line =~ /regExp/ list << line if matched > 0 matched = matched > 2 ? -1 : matched + 1 } end puts list -- Bill Guindon (aka aGorilla) The best answer to most questions is "it depends".