From: Adam Shelly Date: 2008-03-08T02:58:38+09:00 Subject: Re: IO#Foreach -- Max line length On 3/6/08, Peņa, Botp wrote: > On Behalf Of Tristin Davis: > # But by the time you actually get count, isn't the line > # already read in > # memory. So if the line is 7 gigabytes, it'll probably crash > # the system. > > read will accept arg on how many bytes to read. > > so how about, > ... > irb(main):043:0> File.open "test.rb" do |f| while x=f.read(2); p x; end; end That solution essentially ignores linebreaks. If you want to read up to a linebreak or N characters, whichever comes first, you could one of these: ------ class IO #read by characters def for_eachA(linelen) c=0 while (c) buf='' linelen.times { break unless c=getc buf<