7stud -- wrote:
> M. Q. wrote:
>> IO.gets steps through a file one line at a time.
> 
> As does IO.foreach.  And IO.foreach's block terminates naturally when 
> the end of the file is reached:
> 
> IO.foreach("data.txt") do |line|
>   puts line
> end
> 

..and foreach closes the file for you automatically.
-- 
Posted via http://www.ruby-forum.com/.